Regular Expression -- How to Configure for the User

Hi All,

I want to provide a configuration File to find
Find and Replace various pattern.

for example,

if the configuration like below:

###  Paramter = Search Pattern|Replace Pattern ##Comment for user

Parameter = <test1>all-text</test1>|<test2>all-text</test2>
Parameter = <test3>all-text</test3>|<test4>all-text</test4>

I need to transfer the,

   all-text in Search Pattern to (.*?);
   all-text in Replace Pattern to $1;

I am doing everything right....after printing the two Variable
$FindString and $ hold the correct pattern
like below:

$FindString = <test1>(.*?)</test1>
$ReplaceString = <test2>$1</test2>

When I have test this with my input like below:

$Line = "This is the example <test1>Sample text</test1> in this context";
$Line =~ s/$FindString/$ReplaceString/g;

But, when I printed the $Line varible the output
is like below:

"This is the example <test2>$1</test2> in this context";

how to change the my regular expression to
get <test2>Sample text</test2>....why it's retaining the $1 special variable there....!!

Any Help will be highly appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Please check again, I ran the following code and it worked absolutely fine :

#!/usr/local/bin/perl5 -w
$Line = "This is the example <test1>Sample text</test1> in this context";
$Line =~ s/<test1>(.*?)<\/test1>/<test2>$1<\/test2>/g ;
print $Line ;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
$ReplaceString = '"<test2>$1</test2>"';
$Line =~ s/$FindString/$ReplaceString/gee;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.