in reply to Re^2: problem with optional capture group
in thread problem with optional capture group
Win8 Strawberry 5.8.9.5 (32) Tue 12/22/2020 16:43:09 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings for my $line ( '<div id="foo-bar-321" class="bin-boff"></div>', '<div id="foo-bar-321" class="bin-boff"> </div>', '<div id="foo-bar-321" class="bin-boff">foo</div>', '<div id="foo-bar-321" class="bin-boff"> foo </div>', '<div id="foo-bar-321" class="bin-boff">', '<div id="foo-bar-321" class="bin-boff"> ', '<div id="foo-bar-321" class="bin-boff">foo', '<div id="foo-bar-321" class="bin-boff"> foo', ) { if ($line =~ m{ <div (?: (?! </div) .)+ (</div)? }xms) { print "line matched \n '$&' \n"; if (defined $1) { print " right after match, \$1 is defined '$1' \n"; } } } ^Z line matched '<div id="foo-bar-321" class="bin-boff"></div' right after match, $1 is defined '</div' line matched '<div id="foo-bar-321" class="bin-boff"> </div' right after match, $1 is defined '</div' line matched '<div id="foo-bar-321" class="bin-boff">foo</div' right after match, $1 is defined '</div' line matched '<div id="foo-bar-321" class="bin-boff"> foo </div' right after match, $1 is defined '</div' line matched '<div id="foo-bar-321" class="bin-boff">' line matched '<div id="foo-bar-321" class="bin-boff"> ' line matched '<div id="foo-bar-321" class="bin-boff">foo' line matched '<div id="foo-bar-321" class="bin-boff"> foo'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: problem with optional capture group
by Special_K (Pilgrim) on Dec 23, 2020 at 16:31 UTC | |
by AnomalousMonk (Archbishop) on Dec 23, 2020 at 20:54 UTC |