[R] why the "[^\\d]" is not equal to "[^0-9]" in R regular expression?
William Dunlap
wdunlap at tibco.com
Sun Dec 29 19:09:34 CET 2013
Use perl=TRUE if you want \\d to mean something special (a digit) in a regular expression.
> identical(gregexpr(pattern="[^0-9]","+12345ty"), gregexpr(pattern="[^\\d]","+12345ty",perl=TRUE))
[1] TRUE
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of luofeiyu
> Sent: Sunday, December 29, 2013 3:42 AM
> To: R-help at r-project.org
> Subject: [R] why the "[^\\d]" is not equal to "[^0-9]" in R regular expression?
>
> gregexpr(pattern="[^0-9]","+12345ty")
> [[1]]
> [1] 1 7 8
> attr(,"match.length")
> [1] 1 1 1
> attr(,"useBytes")
> [1] TRUE
> gregexpr(pattern="[^\\d]","+12345ty")
> [[1]]
> [1] 1 2 3 4 5 6 7 8
> attr(,"match.length")
> [1] 1 1 1 1 1 1 1 1
> attr(,"useBytes")
> [1] TRUE
>
> why the pattern `[^\\d]` has no same effect as of `[^0-9]` ?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list