in reply to Re: Tidying and simplifying a regular expression
in thread Tidying and simplifying a regular expression

> One reason (maybe the only reason) that the stringization of a  qr//  object comes wrapped in its own little non-capturing group is so that the further interpolation of something like

> ( examples with appended quantifiers )

Not really.

perlre is actually quite explicit about the why

> > > The caret tells Perl that this cluster doesn't inherit the flags of any surrounding pattern, but uses the system defaults (d-imnsx ), modified by any flags specified.

In other words: It's about preserving the flags of the embedded regex and assuming default if none are specified.

Update demonstration

DB<7> $U=qr/U/ # always upper case DB<8> $i=qr/i${U}i/i # surrounding case insensitive DB<9> p $i (?^ui:i(?^u:U)i) DB<10> p 'iui' =~ $i DB<11> p 'iUi' =~ $i 1 DB<12> p 'IUI' =~ $i 1 DB<13> p 'IuI' =~ $i DB<14> p join "\n", grep { $_ =~ $i } <{i,I}{u,U}{i,I}> iUi iUI IUi IUI

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Tidying and simplifying a regular expression
by AnomalousMonk (Archbishop) on Dec 10, 2017 at 05:02 UTC
    It's about preserving the flags of the embedded regex ...

    Yes, and the reason that is done is, at least in part, to make composition of relatively more complex regexes from simpler  qr// components (via interpolation) work "right."


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

      > composition of relatively more complex regexes from simpler  qr//  components (via interpolation)

      The "interpolation" part is surprising and irritating me here.

      I was somehow expecting that an already compiled simpler regex doesn't need to be stringified and interpolated again.

      But this approach is surely easier to achieve and most probably more robust.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery