P
Peter Tuente
Hi Zapanaz,
the default behaviour of regular expression terms is to be "greedy", so to
suppress this behaviour to become "not greedy" you have to apply a single
question mark "?" right after the desired expression(s). Sounds some kind of
complex, but I hope you get me ;-)
In your case the following should be sufficient:
# old: if($content =~ /.*(<a.*<\/a>).*/i){
$anchorContent = $1;
# new:
if($content =~ /.*?(<a.*?<\/a>).*/i){
$anchorContent = $1;
The effect is, that the first expression ".*" becomes not so greedy eating
all the possible chars (incl. one/some "<a" chars that prefix the last
occurrence of "<a" in the current line). Same with the second ".*".
Hope this helps ;-)
Bye.
PiT
the default behaviour of regular expression terms is to be "greedy", so to
suppress this behaviour to become "not greedy" you have to apply a single
question mark "?" right after the desired expression(s). Sounds some kind of
complex, but I hope you get me ;-)
In your case the following should be sufficient:
# old: if($content =~ /.*(<a.*<\/a>).*/i){
$anchorContent = $1;
# new:
if($content =~ /.*?(<a.*?<\/a>).*/i){
$anchorContent = $1;
The effect is, that the first expression ".*" becomes not so greedy eating
all the possible chars (incl. one/some "<a" chars that prefix the last
occurrence of "<a" in the current line). Same with the second ".*".
Hope this helps ;-)
Bye.
PiT