Bod has asked for the wisdom of the Perl Monks concerning the following question:
I've had cause to run some code from the console that usually only gets run on a webserver. In its usual environment, it doesn't give me warnings. But, from the console, I get a warning...
$result =~ s/(Mr(s)?) a/\1 A/s; \1 better written as $1 at...
I have always been under the impression (or perhaps illusion) that \1 should be used within the regular expression and $1 outside of it. Like this:
if ($test =~ /some_test/) { $foo = $1; }
Has something changed in the preferred way to capture in a regular expression, or have I been doing it wrong all the time?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capture Groups
by jo37 (Curate) on Nov 14, 2023 at 20:29 UTC | |
by Bod (Parson) on Nov 14, 2023 at 23:35 UTC | |
by ikegami (Patriarch) on Nov 15, 2023 at 03:51 UTC | |
|
Re: Capture Groups
by eyepopslikeamosquito (Archbishop) on Nov 14, 2023 at 21:52 UTC | |
by Bod (Parson) on Nov 14, 2023 at 23:50 UTC | |
by NetWallah (Canon) on Nov 15, 2023 at 00:07 UTC | |
by soonix (Chancellor) on Nov 15, 2023 at 10:46 UTC | |
|
Re: Capture Groups
by eyepopslikeamosquito (Archbishop) on Nov 15, 2023 at 04:05 UTC |