Ungreedy still too greedy
Posted: Thu Feb 23, 2012 9:27 am
Hi everyone,
I have used following PHP regex command:
My expected/wished result is:
The real result is as follows:
Therefore the replacement was too greedy, because it also replaced item2, instead of only replacing item3. Why is this? And how to rewrite the regex pattern in order to only replace item3?
Thanks and kind regards,
janosh
I have used following PHP regex command:
Code: Select all
$returnValue = preg_replace('/,.*3,/U', ',[replaced],', 'item1,item2,item3,item4,item5');Code: Select all
item1,item2,[replaced],item4,item5Code: Select all
item1,[replaced],item4,item5Thanks and kind regards,
janosh