Home: Perl Programming Help: Regular Expressions:
Suggest any Regular Expression, Please



tallamohan
New User

Jul 22, 2012, 9:27 AM


Views: 9276
Suggest any Regular Expression, Please

$val1="abc";
$val2="xyz";
$val3="abcpqrxyz";


I want to compare val1 and val2 with val3 and
it should return the middle characters which is not common from both the strings....

ex: pqr


wickedxter
User

Aug 1, 2012, 2:26 PM


Views: 9011
Re: [tallamohan] Suggest any Regular Expression, Please


Code
 
my $var1 = 'abc';
my $var2 = 'xyz';
my $var3 = 'abcdexyz';

my @array = ($var1, $var2);
my @match = grep {$var3 =~ /$_/} @array;

print "This match was found $_" for @match;

This is what i came up with...


(This post was edited by wickedxter on Aug 1, 2012, 2:27 PM)


BillKSmith
Veteran

Aug 1, 2012, 2:47 PM


Views: 9007
Re: [tallamohan] Suggest any Regular Expression, Please

Is this what you mean?


Code
 my ($return) = $val3 =~ /$val1 (.*) $val2/x;

Good Luck,
Bill