Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim search wildcard match first occurrence

Tags:

regex

vim

search

I have a file that <a href="blah.com" rel="blahblah" style="textdecoration:none;">blah</a>

I want to match rel="blahblah"

but when i do \rel=".*" it matches rel="blahblah" style="textdecoration:none;"

I have tried rel=".*\{-\}" but that gives an error nested \{

like image 746
mazlix Avatar asked Jun 08 '11 19:06

mazlix


2 Answers

You can use:

rel=".\{-}"

\{-} is used for non-greedy match in VIM

like image 60
anubhava Avatar answered Sep 29 '22 21:09

anubhava


Try [^"] instead of .. The latter is "greedy" and will match as many characters as possible.

The [d-r13579] in regexps is used to match "character classes": in this case any small case letter in the range from d to r or an odd digit. If you start the class with a ^ then it negates the meaning.

Thus [^"] means a character except a double quote, and "[^"]*" means two double quotes with any number of arbitrary characters between them, except double quotes.

like image 30
bandi Avatar answered Sep 29 '22 21:09

bandi