php - Don't match the URL's between BBCode tags -


as title says want pattern match url's in string, except ones between bbcode tags.

so far have made pattern doesn't match url's between [img] tags, have no enough regex skills make work tags more advanced onces ([url=xxx]yyy[/url] , such). clear: nothing between [ , ] should match.


here working example not match url's between [img] tag:

http://regexr.com/v1?38mae (may have paste below pattern due encoding being messed up)

pattern:

(?<!\[img])(((http|ftp|https):\/\/)|www\.)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#!]*[\w\-\@?^=%&/~\+#])

i'd appreciate kind of help!

you can add @ begining of pattern:

\[[^]]*](*skip)(*fail)| 

this subpattern find between square brackets, make pattern fail , force not retry substring.

example pattern (with ~ delimiter):

$pattern = '~\[[^]]*](*skip)(*fail)|              (?<!\[img])              (?:(?:ht|f)tps?://|www\.)              [\w-]+              (?:\.[\w-]+)+              [\w-.,@?^=%&:/\~+#!]*[\w-@?^=%&/\~+#]~xiu'; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -