
01-22-2009
|
|
Registered User
|
|
Join Date: Aug 2008
Location: Bangalore, INDIA
Posts: 55
|
|
Quote:
Originally Posted by KevinADC
In the regexp you see ,?. In this context the ? symbol is a quantifier that means zero or one of whatever is to the left of it. So it will match zero or one comma.
In your regexp you have used .* which means to match zero or more of anything as much as possible. This is called greedy matching. So it matches whatever is between the first single quote and the last single quote in the string. What you should have done was used .*? which means to match zero or more of anything but as little as possible. This is called stingy matching. But using the negated character class [^'] is actually more efficient then using .*? to achieve the same result.
|

Thanks agn Kalvin! The below is the new one I need to solve. Here the same type of string is present but I want the o/p differently.
my $str = " c1 ='mmdnn, ,sdm = sm,m,jkjk',c2 = 'chj=kjk, khj ', c3='hhshhj, hsjh'";
print "Before substitution-> $str\n";
$str =~ s/[^= *'[^']*'] *, *?/:/g;
print "After substitution-> $str\n"; # Getting Wrong o/p
================================
But I need the o/p:
c1 ='mmdnn, ,sdm = sm,m,jkjk':c2 = 'chj=kjk, khj ':c3='hhshhj, hsjh'
|