^ |
The start-of-line marker |
^tux matches any line that starts with tux |
$ |
The end-of-line marker |
tux$ matches any line that ends with tux |
. |
Matches any one character |
Hack. matches Hack1,Hacki but not Hack12,Hackil; only one additional character matches |
[] |
Matches any one of the character set inside [] |
coo[kl] matches cook or cool |
[^] |
Exclusion set: the carat negates the set of characters in the square brackets; text matching this set will not be returned as a match |
9[^01] matches 92,93 but not 91 and 90 |
[-] |
Matches any character within the range specified in [1-5] matches any digits from 1 to 5 |
? |
The preceding item must match one or zero times |
colou?r matches color or colour but not colouur |
+ |
The preceding item must match one or more times |
Rollno-9+ matches Rollno-99,Rollno-9 but not Rollno- |
* |
The preceding item must match zero or more times |
co*l matches cl,col,coool |
() |
Creates a substring in the regex match |
Explained below,in the section “Substring match and back-referencing” |
{n} |
The preceding item must match exactly n times |
[0-9]{3} matches any three-digit number. This can be expanded as: [0-9][0-9][0-9] |
{n,} |
Minimum number of times that the preceding item should match |
[0-9]{2,} matches any number that is two digits or more in length |
Specifies the minimum and maximum number of times thepreceding item should match |
matches any number that is between two and five digits in length |
| |
Alternation ― one of the items on either side of | should match |
Oct (1st|2nd) matches Oct 1st or Oct 2nd |
|
The escape character for escaping any of the special characters given above |
a.b matches a.b but not ajb. The dot is not interpreted as the special “match any one character” regex shown above,but instead a literal dot (period) ASCII character is sought to be matched. Another example: if you’re searching for the US currency symbol “$”,and not the end-of-line marker,you must precede it with a back-slash,like this: $ |