0

I have a huge text file with Roman numbers for the paragraphs and I want to substitute them:

text text ... text

I

text ...

II

and so on

My question is: what regular expression describes one Roman number per line?

In other hand this one /^\vM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$ seems to be ok, except that it includes all blank lines. How refactor it in a way to exclude the empty lines?

1 Answer 1

1

You can use a look-behind assertion to check the length of the matched string:

\v^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$.@<=

. means match any one character (i.e., zero characters will not work).

@<= means look behind and accept only if the preceding atom (i.e., .) matches text immediately before this position in text.

This assertion will fail if the line is empty.

Your Answer

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.