Python regular expression again - match url part II
Ok. I get regexp from here开发者_开发问答 (only WWW links, second version). Everything is fine, except one thing, it parse BBCode too.
Regexp
(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
What fails
[img]http://example.foo/something.png[/img]
When I apply regexp I get http://example.foo/something.png[/img and that's fail. :P Any regexp guru there?
This is a little rough, but try this:
$preg = "%(?:https?://|www\d{0,3}.)(?:[\/A-Za-z0-9-_.]+(?!(?:<|\[/([A-Za-z0-9])+?\1)))%";
I've tested it and it should work as expected if I understood your question correctly.
精彩评论