in reply to Re: Pattern matching
in thread Pattern matching

That doesn't work. Since you don't capture .*, your look-behind is identical to m/tom.*(dick|harry|john)/. You also can't put a regexp inside a look-behind, IIRC.

' tom harry ' =~ m/(?<=tom).*(dick|harry|john)/ && print(1, $/); # + 1 ' harry tom ' =~ m/(?<=tom).*(dick|harry|john)/ && print(2, $/); # + (nothing)

Lookahead works, though

' tom harry ' =~ m/(?=.*tom).*(dick|harry|john)/ && print('A', $/); + # A ' harry tom ' =~ m/(?=.*tom).*(dick|harry|john)/ && print('B', $/); + # B

Replies are listed 'Best First'.
Re^3: Pattern matching
by Hena (Friar) on Jan 07, 2005 at 05:53 UTC
    True. Didn't realize that you could get both sides with lookahead. But I was just trying to get the A part working :).