Metacharacter | Function | Example | What It Matches |
---|---|---|---|
^ | Beginning-of-line anchor | '^love' | Matches all lines beginning with love. |
$ | End-of-line anchor | 'love$' | Matches all lines ending with love. |
. | Matches one character | 'l..e' | Matches lines containing an l, followed by two characters, followed by an e. |
* | Matches zero or more characters preceding the asterisk | ' *love' | Matches lines with zero or more spaces, followed by the pattern love. |
[ ] | Matches one character in the set | '[Ll]ove' | Matches lines containing love or Love. |
[^] | Matches one character not in the set | '[^A–K]ove' | Matches lines not containing a character in the range A through K, followed by ove. |
< | Beginning-of-word anchor | ' | Matches lines containing a word that begins with love. |
> | End-of-word anchor | 'love>' | Matches lines containing a word that ends with love. |
(..) | Tags matched characters | '(love)ing' | Tags marked portion in a register to be remembered later as number 1. To reference later, use 1 to repeat the pattern. May use up to nine tags, starting with the first tag at the leftmost part of the pattern. For example, the pattern love is saved in register 1 to be referenced later as 1. |
x{m} x{m,} x{m,n}[a] | Repetition of character x: m times, at least m times, or between m and n times | 'o{5}' 'o{5,}' 'o{5,10}' | Matches if line has 5 occurences of o, at least 5 occurences of o, or between 5 and 10 occurrences of |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8730/viewspace-1034283/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8730/viewspace-1034283/