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