开发者

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

开发者 https://www.devze.com 2023-01-18 01:52 出处:网络
I want match开发者_运维问答 my @array = ( \'Tree\' , \'JoeTree\',\'Joe\'); foreach (@array ) { if ( $_ =~ /^(Joe)[^Tree]/gi) {

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

精彩评论

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