in reply to Re^3: about style: use possessive or atomic?
in thread about style: use possessive or atomic?

The whole discussion is quite confusing because greediness and atomic grouping are messed up.

Could you please show a use case where you want to avoid backtracking into a once matched group (thats what atomic/possessive is about)

answering your question

> Is it true that ($match){1}+ equals to simply $match?

No!

DB<125> $_ = "a"x5 => "aaaaa" DB<126> $match = "(a+)" => "(a+)" DB<128> $_ =~ /${match}a/ => "aaaa" DB<129> $_ =~ /${match}{1}a/ => "aaaa" DB<130> $_ =~ /${match}{1}+a/ DB<131> $_ =~ /(?>${match})a/ DB<132>

It seems to show that perlre is wrong with the redundant anotation.¹

edit

Answering your root question, IMHO using + as a second quantifier like in a++ only makes sense if you already need to use a first quantifier in the first level of interpolation, like in

($pat1)++($pat2)*+

i.e. + and * are not part of a sub-pattern $patN.

Otherwise I'd always prefer

(?>$pat1)(?>$pat2)

using something like ($pat){1}+ seems quite confusing for me.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

¹) if "redundant" is supposed to mean line 131 and 130 are equivalent, then redundant is a misleading wording

Replies are listed 'Best First'.
Re^5: about style: use possessive or atomic?
by rsFalse (Chaplain) on Aug 16, 2015 at 13:41 UTC
    I used a bigger regex, which contained some such groups. And for avoiding unexpected results, I wanted to use atomics/possessives. And I wanted to capture these groups. So instead of writing /(?> ($pat1) ) (?> ($pat2) )/x I decided to use possessive quantifiers to increase readability :) (my eyes dislike too many parentheses)
    I don't have access to code, where I used it, but friend wrote to me, that with perl 5.20 he gained something wrong (warning/error).
      > but friend wrote to me, that with perl 5.20 he gained something wrong (warning/error).

      Couldn't you make this clear from the beginning?

      > don't have access to code,

      Then please reproduce it next time.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        To by honest, I don't remember. And it is possible that I used that construct redundantly or I used it with wrong faith that after possessive quantifier succeeds then all backtrackings are disabled from this point (but for real backtrackings are disabled only in that group).
        Today I failed to imagine practical example where this atomic/possessive construct could be used.
        So I accessed today to the code.
        It was a regular expression which tries to match (number1) with (measuring units1){optional}, and (number2 with units2){optional}.
        The shortened for simplicity regex looks like that:
        /^ (?: ' \s* )? ($positive_number){1}+ \s* (?: \( \s* ($stdev) \s* \) )? \s* ($units_1)? ( \s* ($positive_number) \s* (?: \( \s* ($stdev) \s* \) )? \s* ($units_2) )? (?: \s* ' )? $/x
        For example: $units_1 = "A|B3"; $units_2 = "C|D-3"; Then regex should match:
        20B3 20 B3 15 D-3 20A15C
        but it shouldn't match 20C.
        With new backtracking it matches 20C as (2, undef, undef, 0, undef, C) === ($1, $2, $3, $4, $5, $6)