There are some special characters in Regular Expressions.Within a pattern,all characters except .,|,(,),[,],{,},+,\,^,$,*,and ? match themselves.They are the special characters.If you know their meaning in the Regular Expressions you can know why are they special.If you want to use themselves in patterns,you need add '\' before them.The following are the meaning of them:
- '.':represents any character except a newline
- '|':Its meaning is 'or'
- '(' and ')':
- '[' and ']':A character class is a set of characters between brackets:[characters] matches any single character between the brackets.
- '{' and '}':
- '+':follow a character or a () expression to express the character or expression must contains more than one times.
- '\':
- '^':a anchor.match the begining of a line
- '$':a anchor.match the end of a line or ...
- '*':
- '?':
Copy the list of these from <the ruby way>:
-
^ Beginning of a line or string
-
$ End of a line or string
-
. Any character except newline (unless POSIX)
-
\w Word character (digit, letter, or underscore)
-
\W Non-word character
-
\s Whitespace character (space, tab, newline, and so on)
-
\S Non-whitespace character
-
\d Digit (same as [0-9])
-
\D Non-digit
-
\A Beginning of a string
-
\Z End of a string or before newline at the end
-
\z End of a string
-
\b Word boundary (outside [ ] only)
-
\B Non-word boundary
-
\b Backspace (inside [ ] only)
-
[ ] Any single character of set
-
* Zero or more of the previous subexpression
-
*? Zero or more of the previous subexpression (non-greedy)
-
+ One or more of the previous subexpression
-
+? One or more of the previous subexpression (non-greedy)
-
{m,n} M to n instances of the previous subexpression
-
{m,n}? M to n instances of the previous subexpression (non-greedy)
-
? Zero or one instance of the previous regular expression
-
| Alternatives
-
( ) Grouping of subexpressions
-
(?# )