in reply to regex problem
Another solution involves a negative lookahead assertion (see perlre):
The (?!f) part imposes a zero-width condition on the match: it must not be followed by the character 'f'. The difference between this solution and /^if[^f]/ is that the latter regex fails on the string 'if'. In other words, with the negative lookahead, the match has length 2, whereas with a (negative) character class the match has length 3.if ( /^if(?!f)/ ) { # begins with if (but not with iff) } else { # anything else }
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex problem
by monarch (Priest) on Jun 08, 2005 at 12:54 UTC |