I have a wysiwyg editor in my back end, and it is tripping up the first regular expression I wrote. This is in PHP4, using preg_replace()
. I\'m capturing the UR
this should match it alright:
/]*)href="https?:\/\/([^"]*)"(.*?)>(.*?)<\/a>/
The useful thing here is the lazy match. *?
it means that it'll match only as much as it absolutely needs to, as opposed to the regular match, which is greedy.
To demonstrate, with this text:
a b c d a b c d
these regexes will have different results:
/a.*c/ selects: "a b c d a b c"
/a.*?c/ selects: "a b c"