Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Capture Groups

by jo37 (Deacon)
on Nov 14, 2023 at 20:29 UTC ( [id://11155621] : note . print w/replies, xml ) Need Help??

in reply to Capture Groups

I have always been under the impression (or perhaps illusion) that \1 should be used within the regular expression and $1 outside of it.

That is correct. But you used \1 in the replacement part of a substitution, which is certainly outside the regex.



Replies are listed 'Best First'.
Re^2: Capture Groups
by Bod (Parson) on Nov 14, 2023 at 23:35 UTC
    But you used \1 in the replacement part of a substitution

    So it's a conceptual problem...I was thinking of the whole of the substitution as being part of the regex...

      It's part of the substitution operator, but the regular expression pattern passed to that operator is (Mr(s)?) a.