What is a regular expression pattern for rule 'doesn't contain a word W'? [closed]

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

  •  29-06-2022
  •  | 
  •  

سؤال

I want to test the web-element style: it shouldn't contain words "disabled" or "inactive".

هل كانت مفيدة؟

المحلول 2

Do you really need a "negative" regex? Why not create a regex that tests that it contains "disabled" or "inactive", and test for it to be false?

'status: inactive' !~ /(disabled|inactive)/

نصائح أخرى

Using negative lookahead:

>> 'status: inactive ' =~ /(?!.*(disabled|inactive))^/
=> nil
>> 'status: disabled' =~ /(?!.*(disabled|inactive))^/
=> nil
>> 'status: enabled' =~ /(?!.*(disabled|inactive))^/
=> 0
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top