Data Science Desktop Survival Guide
by Graham Williams |
|||||
Regexp Character Classes |
Character Class | Description | |
1 | [0-9] | Digits |
2 | [a-z] | Lower-case letters |
3 | [A-Z] | Upper-case letters |
4 | [a-zA-Z] | Alphabetic characters |
5 | [^ a-zA-Z] |
Non-alphabetic characters |
6 | [a-zA-Z0-9] | Alphanumeric characters |
7 | [ntrfv] | Space characters |
8 | [!,:;`)}@-]$*+.?[^ {(#%&˜_/='] |
Punctuation characters |
s <- c("abc12", "@#$", "345", "ABcd")
grep(pattern="[0-9]+", s, value=TRUE)
grep(pattern="[A-Z]+", s, value=TRUE)
grep(pattern="[^@#$]+", s, value=TRUE)
R also supports the use of POSIX character classes which are represented within [[]] (double braces). |
grep(pattern="[[:alpha:]]", s, value=TRUE)
grep(pattern="[[:upper:]]", s, value=TRUE)
|