Inconsistency between engines when using reluctant quantifier in negative look ahead

StackOverflow https://stackoverflow.com/questions/21332355

  •  02-10-2022
  •  | 
  •  

Question

I found something odd when using a reluctant quantifier in a negative look ahead.

When creating a regex to assert a maximum of 3 uppercase characters, I devised this:

^(?!(.*?[A-Z]){4}).*$

which works on rubular, but not on regex101.

Why is that?

Était-ce utile?

La solution

^, $ matches beginning/end of line in Ruby.

While in another languages, ^, $ matches the beginning/end of the string unless multiline mode (m) is specified. (Some regular expression engine requires g flag to match multiple times.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top