Loading ...
Sorry, an error occurred while loading the content.

Re: regex capture \1 versus $1

Expand Messages
  • acummingsus
    ... [ why the error ] ... regex, but ... 1 is a part of a capturing group. And, capture group is part of the m for match a.k.a regex a.k.a. m/(.) 1/;
    Message 1 of 4 , Aug 1, 2005
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, Jeff 'japhy' Pinyan <japhy@p...>
      wrote:
      > On Aug 1, acummingsus said:
      [ why the error ]
      > It's not an error, it's a warning.
      >
      > > \1 better written as $1 at /home/al/bin/wthr_pbml line 9.
      > > \2 better written as $2 at /home/al/bin/wthr_pbml line 9.
      >
      > Because Perl prefers you use $<DIGIT> outside of the *actual* regular
      > expression. The right-hand side of an s/// is not parsed as a
      regex, but
      > as a double-quoted string. You should use *variables* there, not the
      > regex escape sequence denoting a capturing group.

      \1 is a part of a capturing group. And, capture group is part of the
      m for match a.k.a "regex" a.k.a. m/(.)\1/; a.k.a. s/(.)\1//;

      The right hand portion of a substitution, however, is *not* defined as
      "regex". And, said right hand portion differs from the left hand
      portion in that the left hand portion *is* "regex".

      So, now I know what I didn't know back then which is that
      *I_formerly_did_not_know* that the right hand portion of a
      substitution is *not* "regex".

      So, as a beginner, I *formerly* didn't have/own sufficient definition
      and/or context of what "regex" is when, on not this but a different
      beginner group, I was told "\1 must be used within the regex itself".

      Super! Thank you! And, HTH someone, some how, in some way.

      Alan.
    Your message has been successfully submitted and would be delivered to recipients shortly.