开发者

How can I make part of a Perl regular expression negative optional?

I want match开发者_运维问答

my @array = ( 'Tree' , 'JoeTree','Joe');

    foreach (@array ) {
      if ( $_ =~ /^(Joe)[^Tree]/gi) {
        print "matched $_";
      }
    }

It matching only Joe. it should not matching anything else


You dont need regular expressions for this:

if ($_ eq 'Joe') {
    print "matched $_";
}  


Match only 'Joe' as the whole text?

/^(Joe)$/

or match 'Joe' as the word alone?

/\b(Joe)\b/

or match 'Joe' not followed by 'Tree'?

/^(Joe)(?!Tree)/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜