CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [kennychen614] Issues :matching variable $1,$2,... in replacement string: Edit Log



Zhris
Enthusiast

Apr 20, 2011, 6:55 AM


Views: 10447
Re: [kennychen614] Issues :matching variable $1,$2,... in replacement string

I'm not really sure how you would do it without using multiple expressions, or with user input, maybe there is a way using eval.

Here is my method which uses 2 expressions, but no user input:


Code
my $string = q/There are 3 boys/; 

my $search = q/\b(\d+)\b/;
$string =~ m/$search/;
my $replace = qq/$1 of 10/;
$string =~ s/$search/$replace/g;

print "$string";


I'm not sure if you will find this helpful. Others may have suggestions.

Chris


(This post was edited by Zhris on Apr 20, 2011, 7:16 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Apr 20, 2011, 7:01 AM
Post edited by Zhris (Enthusiast) on Apr 20, 2011, 7:01 AM
Post edited by Zhris (Enthusiast) on Apr 20, 2011, 7:08 AM
Post edited by Zhris (Enthusiast) on Apr 20, 2011, 7:16 AM
Post edited by Zhris (Enthusiast) on Apr 20, 2011, 7:16 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives