perl negative look behind with groupings

Posted by user1539348 on Stack Overflow See other posts from Stack Overflow or by user1539348
Published on 2012-12-14T23:01:54Z Indexed on 2012/12/14 23:03 UTC
Read the original article Hit count: 168

Filed under:
|
|

I have a problem trying to get a certain match to work with negative look behind

example

@list = qw( apple banana cherry); 
$comb_tlist = join ("|", @tlist);
$string1 = "include $(dir)/apple";
$string2 = "#include $(dir)/apple";

if( string1 =~ /^(?<!#).*($comb_tlist)/)   #matching regex I tried, works

The array holds a set of variables that is matched against the string.

I need the regex to match $string1, but not $string2. It matches $string1, but it ALSO matches $string2. Can anyone tell me what I am attempting wrong here. Thanks!

© Stack Overflow or respective owner

Related posts about regex

Related posts about perl