[tpm] Greedy regex question
Madison Kelly
linux at alteeve.com
Fri Feb 29 08:07:19 PST 2008
Hi all,
Given the string:
$val="0 (0x0) (int)";
Why does:
$val=~s/\(.*?\)//;
Properly, ungreedily, return "0 (int)" *but*, changing it to:
$val=~s/\(.*?\)$//;
Wrongly, greedily, return "0 "? When I put the '.*?' in brackets and
print '$1' on the later it is indeed grabbing "0x0) (int".
What is it about anchoring the regex to the end of the string cause
it to be a greedy regex again? As you can probably gather, I am trying
to get rid of /only/ the last '(foo)' in a given string.
Thanks!
Madi
More information about the toronto-pm
mailing list