Let's dig deeper into regex:
Symbol |
Meaning |
. |
Any character, except for end of the line |
^ |
The beginning of the line |
$ |
The end of the line |
\_ |
Any character, including end of the line |
< |
The beginning of a word |
> |
The end of a word |
There are also what Vim calls character classes:
Symbol |
Meaning |
s |
Whitespace (Tab and Space) |
d |
A digit |
w |
A word character (digits, numbers or underscores) |
l |
A lowercase character |
u |
An uppercase character |
a |
An alphabetic character |
These classes have the opposite effect when capitalized; for example, D matches all non-digit characters, whereas L matches everything but lowercase letters (note that this is different to just matching uppercase letters).
You can also specify a set of characters explicitly, using square brackets ([]). For instance, [A-Z0-9] will match all uppercase characters and all digits, while [,4abc] will only match commas, the number 4, and letters a, b, and c.
For sequences (such as numbers or letters of the alphabet), you can use a hyphen (-) to represent a range. For instance, [0-7] will include numbers from 0 to 7, and [a-z] will include all lowercase letters from a to z.
Here's one more example, including letters, numbers, and underscores: [0-9A-Za-z_].
Finally, you can negate an entire range by prefixing it with a caret (^). For instance, if you wanted to match all non-alphanumeric characters, you would put [^0-9A-Za-z].