How can I match strings that don't match a particular pattern in Perl?

前端 未结 6 1614
别跟我提以往
别跟我提以往 2021-02-06 00:25

I know that it is easy to match anything except a given character using a regular expression.

$text = \"ab ac ad\";
$text =~ s/[^c]*//g; # Match anything, except         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 00:45

    If you just want to check if the string does not contain "ac", just use a negation.

    $text = "ab ac ad";
    
    print "ac not found" if $text !~ /ac/;
    

    or

    print "ac not found" unless $text =~ /ac/;
    

提交回复
热议问题