Inconsistency between engines when using reluctant quantifier in negative look ahead

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

  •  02-10-2022
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione

^, $ 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.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top