diff options
-rw-r--r-- | mg.c | 9 | ||||
-rw-r--r-- | pod/perlvar.pod | 23 | ||||
-rwxr-xr-x | t/op/pat.t | 7 |
3 files changed, 26 insertions, 13 deletions
@@ -326,8 +326,13 @@ magic_regdata_cnt(SV *sv, MAGIC *mg) register REGEXP *rx; char *t; - if (PL_curpm && (rx = PL_curpm->op_pmregexp)) - return rx->lastparen; + if (PL_curpm && (rx = PL_curpm->op_pmregexp)) { + if (mg->mg_obj) /* @+ */ + return rx->nparens; + else /* @- */ + return rx->lastparen; + } + return (U32)-1; } diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 7100af5b75..8c6305ccad 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -189,13 +189,14 @@ This variable is read-only. $+[0] is the offset of the end of the last successfull match. C<$+[>I<n>C<]> is the offset of the end of the substring matched by -I<n>-th subpattern. +I<n>-th subpattern, or undef if the subpattern did not match. Thus after a match against $_, $& coincides with C<substr $_, $-[0], -$+[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<], -$+[>I<0>C<]> if C<$-[>I<n>C<]> is defined, and $+ conincides with -C<substr $_, $-[-1], $+[-1]>. One can use C<$#+> to find the last -matched subgroup in the last successful match. Compare with L<"@-">. +$+[0] - $-[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<], +$+[>I<n>C<] - $-[>I<n>C<]> if C<$-[>I<n>C<]> is defined, and $+ coincides with +C<substr $_, $-[$#-], $+[$#-]>. One can use C<$#+> to find the number +of subgroups in the last successful match. Note the difference with +C<$#->, which is the last I<matched> subgroup. Compare with L<"@-">. =item $MULTILINE_MATCHING @@ -410,13 +411,15 @@ channel. (Mnemonic: lines_on_page - lines_printed.) $-[0] is the offset of the start of the last successfull match. C<$-[>I<n>C<]> is the offset of the start of the substring matched by -I<n>-th subpattern. +I<n>-th subpattern, or undef if the subpattern did not match. Thus after a match against $_, $& coincides with C<substr $_, $-[0], -$+[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<], -$+[>I<0>C<]> if C<$-[>I<n>C<]> is defined, and $+ conincides with -C<substr $_, $-[-1], $+[-1]>. One can use C<$#-> to find the last -matched subgroup in the last successful match. Compare with L<"@+">. +$+[0] - $-[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<], +$+[>I<n>C<] - $-[>I<n>C<]> if C<$-[>I<n>C<]> is defined, and $+ coincides with +C<substr $_, $-[$#-], $+[$#-]>. One can use C<$#-> to find the last +matched subgroup in the last successful match. Note the difference with +C<$#+>, which is the number of subgroups in the regular expression. Compare +with L<"@+">. =item format_name HANDLE EXPR diff --git a/t/op/pat.t b/t/op/pat.t index a289fbe08d..7bcc196ed1 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -4,7 +4,7 @@ # the format supported by op/regexp.t. If you want to add a test # that does fit that format, add it to op/re_tests, not here. -print "1..176\n"; +print "1..177\n"; BEGIN { chdir 't' if -d 't'; @@ -692,6 +692,11 @@ print "not " print "ok $test\n"; $test++; +/.(a)(ba*)?/; +print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1; +print "ok $test\n"; +$test++; + $str = 'abcde'; pos $str = 2; |