in reply to Re^4: perl indication of end of string already matched
in thread perl indication of end of string already matched
BTW: Another way to determine the start/middle/end position of a matched substring in a string is by using the @- @+ regex special variables; see perlvar.
Play with adding '-'s at the start/end of $s to convince yourself this works.c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'foo--bar--baz'; ;; while ($s =~ m{ (\w+) }xmsg) { printf qq{matched '$1' %s of '$s' \n}, $-[1] == 0 ? 'at start' : $+[1] == length $s ? 'at very end' : 'in middle'; } " matched 'foo' at start of 'foo--bar--baz' matched 'bar' in middle of 'foo--bar--baz' matched 'baz' at very end of 'foo--bar--baz'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: perl indication of end of string already matched (updated)
by haukex (Archbishop) on Jun 09, 2020 at 08:29 UTC |