4

I am trying to write a fold expression, but I can't get the regex to work.

The string I want to check for and the regex are:

# -- Heading 1 --
^.*-{2}\s([\_a-zA-Z0-9]\s*)+\s-{2}$

what syntax do I use to do the check? I tried: (non seemed to work)

if match(line , "\v regex") >= 0 if line =~ "\v regex"

1 Answer 1

4

You can use either match() or =~, but the regexp is wrong.

There is a lot to guess as I don't know all the potential input, but I think you meant:

^.*-\{2}\s\%([_a-zA-Z0-9]\+\s\)\+-\{2}$

Or a slightly different variant using character classes:

^\v.*-- [_[:alnum:][:blank:]]+--$

Or maybe using a negated collection (matching any character but -):

^\v# -- [^-]+ --$

Go wild!

1
  • Thanks. I tried all your regexes, but they also didn't work. Then I figured out the problem was that I had been wrapping them in double quotes. Changed them to single and thew worked fine.
    – AuSaidimu
    Mar 30, 2019 at 13:12

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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