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)/
题
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