October 2012
346 pages
7h 40m
English
| Tip 73 | Use the \v Pattern Switch for Regex Searches |
Vim’s regular expression syntax is closer in style to POSIX than to Perl. For programmers who already know Perl’s regexes, this can be a source of frustration. Using the very magic pattern switch, we can make Vim adopt a more familiar syntax for regular expressions.
Let’s say that we want to compose a regular expression that matches each of the color codes in this snippet of CSS:
| patterns/color.css | |
| | body { color: #3c3c3c; } |
| | a { color: #0000EE; } |
| | strong { color: #000; } |
We need to match a # character followed by either three or six hexadecimal characters. That includes all numeric digits, plus the letters A through F in upper- or lowercase.
The following ...
Read now
Unlock full access