1

I am trying to use regular expressions to find common-markdown elements (I am new to vim & regular expressions).

For example to find a strike-through ~~something~~ I am searching for the following: /\v\~{2}[^\~]+\~{2}

That works great, except it also considers ~~~something~~~ as a strike-through.

After doing some research, I thought I could use < and > to match the whole world. However this doesn't match anything at all /\v<\~{2}[^\~]+\~{2}>

0
2

A fairly robust pattern which works (though is hard to type, I would store it in a variable or something if you need to operate on it often) is

\v([^\~]|^)\zs\~{2}[^\~]+\~{2}\ze([^~]|$)

We use ([^\~]|^) and ([^\~]|$) to make sure the characters on either side of the text are not ~, and we use \zs and \ze to anchor the match to not include those characters.

Reference: :help pattern, specifically :help /\zs and :help /\ze (though I never type the / in the help commands when I'm looking for these).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.