I have stumbled across an unexpected regex behaviour that I hope someone can explain. More specifically, this is the code:
$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;
And this is the output:
I would have expected this, though:
It is not much of a problem as such, as I can always change .+?
or remove the /s
. What I find a bit odd is that the /s
makes the .+?
greedy, despite the +?
. Could someone please enlighten me?