Does Ruby regular expression have a not match operator like "!~" in Perl?

regex, ruby

Solution

Yes: `!~` works just fine – you probably thought it wouldn’t because it’s missing from the documentation page of `Regexp`. Nevertheless, it works:

irb(main):001:0> 'x' !~ /x/
=> false
irb(main):002:0> 'x' !~ /y/
=> true

Problem

I just want to know whether ruby regex has a not match operator just like `!~` in perl. I feel it's inconvenient to use `(?!xxx)`or `(?<!xxxx)` because you cannot use regex patterns in the `xxx` part.

Original source