Regular expressions consist of two basic character types: literal (normal) text characters and metacharacters. Metacharacters enable regular expressions to have processing power. A meta-character is a special character in a regular expression that can be used to specify its leading character (that is, the character in front of the metacharacters) in the target object.
| Vim Meta-character |
grep Meta-character |
Description |
| ^ |
^ |
Match the starting position of the input string |
| $ |
$ |
Match the starting position of the input string |
| * |
* |
Matches the preceding subexpression 0 or n times (n>0) |
| \+ |
\+ |
Matches the preceding subexpression 1 or n times (n>1) |
| \? |
\? |
Match previous subexpression 0 or 1 times |
| \{n} |
\{n\} |
Match determined N Times (n>=0) |
| \{n,} |
\{n,\} |
Minimum match n times (∞>n>=0) |
| \{N,M} |
\{n,m\} |
Match at least n times and up to M (n<m) |
| \< |
\< |
Match the first words of the word |
| \> |
\> |
Match word endings |
| | |
|
or characters, such as: X|y match x or Y |
| [ABC] |
[ABC] |
The character set is combined. Match any one of the characters contained |
| [^ABC] |
[^ABC] |
Represents any character that matches a character other than the characters in square brackets. |
| [A-z] |
[A-z] |
Character range, matching A-Z any character |
| [^a-z] |
[^a-z] |
Represents any character that matches a A-Z character except in square brackets. |
| \d |
----------- |
Matches a numeric character. equivalent to [0-9] |
| \d |
----------- |
Match non-numeric characters |
| \w |
\w |
Match 0-9,a-z,a-z |
| \w |
\w |
Match non-0-9,a-z,a-z |
Vim and grep regular expressions are similar and different