regexvim

Vim Regex for multiple-line quotes followed by punctuation


In my text file, I want Vim to search for a quote that is immediately followed by a period or a comma.

blah blah blah "Don't want 
this" blah blah blah blah 
blah blah blah blah "But 
want this". blah blah blah 

My pattern "\_.\{-}"[.,] fails because it captures everything from the " in the first line to the ". in the last one. In other words, the lazy multi \{-} is still too greedy. How can I make a more precise pattern for what I really want?

PS I do want the quotation marks and the comma/period to be part of the match, but you don't need to worry about grouping on my behalf so long as your solution captures the whole thing. Thanks.


Solution

  • \_. is quite possibly the greediest atom, and \{-} doesn't really change it.

    You can work around it by being more specific than .:

    /"\_[^"]\{-}"[.,]
    

    it's a match