tags:

views:

60

answers:

2

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

+2  A: 

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)/
eumiro
after that i have some strings
Tree
not followed by would be `(?!`
ysth
+6  A: 

You dont need regular expressions for this:

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