Inconsistency between engines when using reluctant quantifier in negative look ahead

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

  •  02-10-2022
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top