in reply to Positive lookbehind and lookahead confusion

In addition to those pointed out by Corion and kcott, there's another little problem with the OPed regex. The first  .* assertion "consumes" all but one of the  \d digits available for  \d+ to match, giving a wrong answer to the question of Life, the Universe and Everything:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = qq{DoGcat\n 42\n birdfIsH}; dd $s; print qq{<<$s>>}; ;; print qq{LUE == '$1'} if $s =~ /(?<=dog) .* (\d+) .* (?=fish)/sxi; " "DoGcat\n 42\n birdfIsH" <<DoGcat 42 birdfIsH>> LUE == '2'
This problem could be solved by either making the first  .* "lazy", as I like to call it:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = qq{DoGcat\n 42\n birdfIsH}; dd $s; print qq{<<$s>>}; ;; print qq{LUE == '$1'} if $s =~ /(?<=dog) .*? (\d+) .* (?=fish)/sxi; " "DoGcat\n 42\n birdfIsH" <<DoGcat 42 birdfIsH>> LUE == '42'
or by being more specific about what this group should match:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = qq{DoGcat\n 42\n birdfIsH}; dd $s; print qq{<<$s>>}; ;; print qq{LUE == '$1'} if $s =~ /(?<=dog) \D* (\d+) .* (?=fish)/sxi; " "DoGcat\n 42\n birdfIsH" <<DoGcat 42 birdfIsH>> LUE == '42'
(I'm also not using the useless  /g modifier.) (Update: Of course, none of this matters if you don't really care what the answer is, only that there is an answer! :)


Give a man a fish:  <%-{-{-{-<