Linux Special characters in regular expressions
Symbol | What it matches or does |
. | Matches any character |
[chars] | Matches any character from a given set |
[^chars] | Matches any character not in a given set |
^ | Matches the beginning of a line |
$ | Matches the end of a line |
\w | Matches any “word” character (same as [A-Za-z0-9_]) |
\W | Matches any character except “word” (same as [^A-Za-z0-9_]) |
\s | Matches any whitespace character (same as [ \f\t\n\r]) |
\S | Matches any character except whitespace (same as [^ \f\t\n\r]) |
\d | Matches any digit (same as [0-9]) |
\D | Matches any character except digit (same as [^0-9]) |
\b | Matches a word boundary, 'py\b' matches 'py', 'py.', or 'py!', but not 'python', 'py1', 'py2' |
\B | Matches aposition that is not a word boundary, 'py\B' matches 'python', 'py1', 'py2', but not 'py', 'py.', or 'py!' |
| | Matches either the element to its left or the one to its right |
(expr) | Limits scope, groups elements, allows matches to be captured |
? | Allows zero or one match of the preceding element |
* | Allows zero, one, or many matches of the preceding element |
+ | Allows one or more matches of the preceding element |
{n} | Matches exactly n instances of the preceding element |
{min,} | Matches at least min instances (note the comma) |
{min,max} | Matches any number of instances from min to max |
\f | Matches a form feed, Used to instruct to start a new page |
\t | Matches a tab |
\n | Matches a new line |
\r | Matches a carriage return |