Regular Expressions |
| Operator |
Description |
Example |
Matches |
Fails |
| . |
Any one character except newline |
. |
k |
|
| ^ |
Start of string |
^T |
^Train |
Car |
| $ |
End of string |
t$ |
Artist |
Train |
| [chars] |
Any character between the square brackets |
[xyzXYZ] |
Y |
A |
| [char range] |
Any character in the range |
[a-zA-Z] |
R |
8 |
| \d |
Any single numeric digit. Shortcut for [0-9] |
\d\d\d |
456 |
Car |
| \w |
Any alphanumeric character or underscore. Shortcut for [a-zA-Z0-9_] |
\w\w\w |
Bus |
60% |
| \s |
Space |
\d\s\d |
1 3 |
123 |
| \b |
Boundary of a word |
\bPhone\b |
Phone |
Phonecall |
| * |
Previous charcter may occur zero or more times. |
joy*car |
jocar |
jcar |
| + |
Previous charcter may occur once or more times |
joy+car |
joyycar |
car |
| ? |
Previous charcter may occur once or not at all |
boats? |
boat |
boa |
| {number} |
Number of repititions of previous character or string |
\d{3}   ("Hi J."){2} |
456   "Hi J.Hi J." |
45 34   Hi K. |
| {min, max} |
Min and max number of repitition of previous character or string |
\w\w{4, 6)   ("Bye T"){2, 3} |
totototo   "Bye T.Bye T." |
twit   "Bye.Bye." |
| \b |
Boundary of a word |
\bPhone\b |
Phone |
Phonecall |