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
In reply to Re: regex problem
by tlm
in thread regex problem
by mosh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |