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

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

  •  29-06-2022
  •  | 
  •  

Pergunta

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

Foi útil?

Solução 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)/

Outras dicas

Using negative lookahead:

>> 'status: inactive ' =~ /(?!.*(disabled|inactive))^/
=> nil
>> 'status: disabled' =~ /(?!.*(disabled|inactive))^/
=> nil
>> 'status: enabled' =~ /(?!.*(disabled|inactive))^/
=> 0
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top