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