develooper Front page | perl.beginners | Postings from March 2002

RE: using search backreferences in a variable

Thread Previous | Thread Next
From:
Bryan R Harris
Date:
March 28, 2002 12:13
Subject:
RE: using search backreferences in a variable
Message ID:
OF85AF6EE4.810D893C-ON07256B8A.006DE91A@rsc.raytheon.com

Jeff, David, Nikola-    I obviously haven't been doing this long, but I
already love perl.  Thanks for the tips.

A couple quick questions:

- Why is the \1, \2, etc. syntax obsolete?  The one thing I love about
regular expressions is that I can use them within text editors (nedit,
textpad, bbedit), but none of these support the $1 notation in the replace
string.  Why aren't re's consistent between perl and text editors?

- What does the "qr" tag do?

Thanks again.

- Bryan

__________________


\1 is obsolete.
try $1 and you  also have use the /ee
and fix your $replace for the /ee
read perldoc perlre

$match = qr/cat(\d+)/;
$replace = '$1. "dog"';
$_ = "cat15";
s/$match/$replace/gee;
print $_, "\n";  # prints -->  15dog

> -----Original Message-----
> From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com]
> Sent: Thursday, March 28, 2002 10:46 AM
> To: Beginners Perl Mailing List
> Subject: using search backreferences in a variable
>
>
>
> Why does this segment not work properly?
>
> $match = "cat(\d+)";
> $replace = "\1dog";
> $_ = "cat15";
> s/$match/$replace/g;
> print $_;  # prints -->  \1dog
>
> Any ideas?
>
> TIA.
>
> - B
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>

----------------------------------------------------------------------------

--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About