pingo has asked for the wisdom of the Perl Monks concerning the following question:
And this is the output:$text = "<a href='http://www.example.com/'>Example 1</a>\n<a href='htt +p://www.example.net/' target='_blank'>Example 2</a>"; my ($a) = $text =~ /<a href='(.+?)' target='_blank'>/s; print "$a\n";
I would have expected this, though:http://www.example.com/'>Example 1</a> <a href='http://www.example.net/
It is not much of a problem as such, as I can always change .+? to [^']+ or remove the /s. What I find a bit odd is that the /s makes the .+? greedy, despite the +?. Could someone please enlighten me?http://www.example.net/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex becomes greedy with /s
by Corion (Patriarch) on Feb 26, 2010 at 10:02 UTC | |
by pingo (Hermit) on Feb 26, 2010 at 10:24 UTC | |
by AnomalousMonk (Archbishop) on Feb 26, 2010 at 23:35 UTC |