Home > Blockchain >  Why Won't the Standard Regex for Roman Numerals Work with Vim?
Why Won't the Standard Regex for Roman Numerals Work with Vim?

Time:05-17

I am using a highly simplistic regex in Vim to find roman numerals in a text file. I simply run the command:

:/^[MDCLXVI] $

It gives me the following error:

E486: Pattern not found: ^[MDCLXVI] $

This is my file:

I
II
III
IV
V
XIII
MVIII

I'm probably doing something very silly. But this does not seem to work for me.

CodePudding user response:

You will need to escape the , unless you are in 'magic' mode, so your options are (using a substitution) for the example:

:%s/^[MDCLXVI]\ $/g

Or using \v for magic mode (actually I usually just keep this on as a default as it makes things a bit easier to remember which ones need to be escaped or not):

:%s/\v^[MDCLXVI] $/g
  • Related