Inconsistency between engines when using reluctant quantifier in negative look ahead

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

  •  02-10-2022
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top