A Ruby regular expression has a mismatch operator, for example, "! ~" In Perl?

I just want to know if the rosy regular expression has a non-matching operator, like !~ In perl. I find it inconvenient to use (?!xxx) or (?<!xxxx) because you cannot use regex patterns in the xxx part.

+79
ruby regex
Dec 07
source share
2 answers

Yes !~ Works just fine - you probably thought it wasnโ€™t because it is not on the Regexp documentation Regexp . However, this works:

 irb(main):001:0> 'x' !~ /x/ => false irb(main):002:0> 'x' !~ /y/ => true 
+145
Dec 07
source share

AFAIK supported (?! Xxx):

 2.1.5 :021 > 'abc1234' =~ /^abc/ => 0 2.1.5 :022 > 'def1234' =~ /^abc/ => nil 2.1.5 :023 > 'abc1234' =~ /^(?!abc)/ => nil 2.1.5 :024 > 'def1234' =~ /^(?!abc)/ => 0 
+3
Feb 06 '15 at 3:04
source share



All Articles