Regular expressions 6. Convenience escape sequences
|
|
Convenience escape sequences in a regular expression present a shorthand for some character classes.
-
\d matches a digit: [0-9].
-
Example: "-?\d+" matches any integer.
-
\D not a digit: [^0-9].
-
\l a letter: [a-zA-Z].
-
\L not a letter: [^a-zA-Z].
-
\s whitespace: [ \t\n\r\f\v].
-
\S not whitespace: [^ \t\n\r\f\v].
-
\w "word" character: [a-zA-Z0-9_].
-
Example: "\w+" matches a "word", i.e., a string of one or more characters that may consist of letters, digits and underscores.
-
\W not a "word" character: [^a-zA-Z0-9_].
-
\B any character that is not a word-delimiter.
Links to this page
© djmw 20010708