in reply to Positive lookbehind and lookahead confusion
G'day Sarah,
There's nothing wrong with either assertion. The apparent problem occurs because the first '.*' matches 'cat' and all the whitespace that follows it but nothing matches 'bird' and all the whitespace that precedes it.
Here's a simplified example of what you're currently doing:
$ perl -E 'say("X\n\t99\n\tY" =~ /(?<=X).*\d+(?=Y)/s ? 1 : 0)' 0
Here's how you might fix that:
$ perl -E 'say("X\n\t99\n\tY" =~ /(?<=X).*\d+.*(?=Y)/s ? 1 : 0)' 1
I'd also suggest you take a look at "perlre: Modifiers": note I only used 's'; the 'gxi' are not needed.
— Ken
|
|---|