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: [ericm] replacement with backreference: Edit Log



eWish
User

Aug 8, 2007, 7:39 PM


Views: 4037
Re: [ericm] replacement with backreference

I may be missing what you are trying to do here.


Code
my $pattern = $field[0];  
my $replacement = $field[1];

my $test = $field[0];

if ($test =~ /^$pattern$/) {

# $& holds the entire regex match.
my $test1 =~ s/$&/$replacement/;

# Or you could use $1 if you would like.
my $test2 =~ s/$1/$replacement/;

print $test1, "\n";
print $test2, "\n";

} else {
print "Did not find a match for $pattern in $test";
}



(This post was edited by eWish on Aug 8, 2007, 7:46 PM)


Edit Log:
Post edited by eWish (User) on Aug 8, 2007, 7:46 PM: spelling


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

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