Regular expressions |
Describe |
Example |
\ |
Escape characters, escaping special characters, ignoring their special meanings |
A\.B matches a.b, but does not match AJB,. Escaped as a special meaning |
^ |
Matches the beginning of the line, awk, ^ is the start of the matching string |
^tux matches lines starting with Tux |
$ |
Matches the end of the line, in Awk, $ is the ending of the matching string |
tux$ matches lines ending with Tux |
. |
Matches any single character except the line break \ n, awk can |
AB. Matches an ABC or bad, does not match ABCD or Abde, only matches single character |
[ ] |
Match any one of the characters contained in [character] |
COO[KL] can match cook or cool |
[^ ] |
Match any character other than [^ character] |
123[^45] can not match 1234 or 1235,1236, 1237 can |
[ - ] |
Matches any character in the specified range of [], to be written as an increment |
[0-9] can match 1, 2 or 3 of any one of the numbers |
? |
Match previous items 1 or 0 times |
Colou?r can match color or colour, and cannot match Colouur |
+ |
Match the previous item 1 or more times |
sa-6+ matches sa-6, sa-666, cannot match sa- |
* |
Match the previous item 0 or more times |
Co*l matches cl, col, cool, coool, etc. |
() |
Match expression to create a substring to match |
MA (tri)? Match Max or Maxtrix |
N |
Matches the previous item n times, n is a positive integer that can be 0 |
[0-9] {3} matches any three-digit number and can be extended to [0-9][0-9][0-9] |
{N,} |
The previous item must match at least n times |
[0-9] {2,} matches any two-digit or more number of digits |
{N,m} |
Specifies that the preceding item matches at least N times, up to M times, n<=m |
[0-9] {2,5} matches any number from a two-digit to a five-digit number |
| |
Alternate Match | Any one of two sides |
AB (C|D) matches ABC or ABD |