- Any single character or string of characters can match the character itself,
- ^ Symbol (
^
) Indicates the start of a row; $ symbol ($
) Indicates the end of a row.
- To search for special characters (such as the $ symbol), you must add a backslash (
\
). For example,\$
Search$
Instead of the end of a row.
- Point (
.
) Represents any single character. For example,ad..n
It represents five character items, the first two characters are "ad", and the last character is "n ". The two characters in the middle can be any character, but can only be composed of two characters.
- At any time, if the regular expression is included in the slash (for example
/re/
), Search is performed in the order of files. If a regular expression is contained in a question mark (for example,?re?
), Search is performed in reverse order of files.
- Square brackets (
[]
) Indicates multiple values, minus signs (-
) Indicates the value range. For example,[0-9]
And[0123456789]
Same,[a-z]
It is equivalent to searching for any lowercase character. If the first character of a list is a ^ symbol, it matches any character that is not in this list.
Table 1 shows how these rules are actually matched.
Table 1. Regular Expression examples
[abc]
Match one of "a", "B", and "c"
[a-z]
Match any lowercase character from "a" to "z"
[A-Z]
Match any uppercase character from "A" to "Z"
[0-9]
Match any number from 0 to 9
[^0-9]
Match any character except 0 to 9 digits
[-0-9]
Match any number from 0 to 9, or a hyphen (-)
[0-9-]
Match any number from 0 to 9, or a hyphen (-)
[^-0-9]
Match any character except numbers and hyphens (-) from 0 to 9
[a-zA-Z0-9]
Match any character or number