I'm trying to find all link definitions in a markdown document:
See you saturday!
I'm using this pattern (taken from Michelf's markdown parser http://michelf.com/projects/php-markdown)::
/
^[ ]{0,3}(?:\[(.+?)\][ ]?:) # id = $1
[ ]*
? # maybe *one* newline
[ ]*
(?:
<(.+?)> # url = $2
|
(\S+?) # url = $3
)
[ ]*
? # maybe one newline
[ ]*
(?:
(?<=\s) # lookbehind for whitespace
["(]
(.*?) # title = $4
[")]
[ ]*
)? # title is optional
(?:
+|\Z)
/xm
Well this works fine until you use urls with relative schema's, in the above input example, preg_match_all
only returns the last link, but with this input:
See you saturday!
It returns all three and I can't see why.
I suspect it has something to with the greedy behaviour of regex's.