Is there a regular expression that matches the url but does not match the image? For example, http://www.abc.com/and http://www.abc.com/images/index.php can all match,
But http://www.abc.com/images/logo.gifcannot match.
The expression I wrote matches with http://www.abc.com/images/logo.
(http\://)?([a-z0-9_-]+\.)+(com|net|cn|org){1}(\/[a-z0-9_-]+)*\.?(?!jpg|jpeg|gif|png|bmp)
Reply to discussion (solution)
Generally, URLs are followed by other irrelevant characters. we recommend that you use this character.
For example:
Http://www.abc.com/images/logo.gif"
(?! : Jpg | jpeg | gif | png | bmp )(? :")
I did not test the environment just now. I wrote it at will. I think it's a problem. I found an environment and wrote another one.
$ S = 'http: // www.abc.com/image/index.php "http://www.abc.com/images/logo.gif "';
Preg_match_all ('#/[^/] * (? <= \....(? Var_export ($ m );
Let's get it done. you can understand it and use it again.
Here \... matches the extension of the dot and three characters. if there is no extension of the dot, or if it is not three characters, find it by yourself.
I did not test the environment just now. I wrote it at will. I think it's a problem. I found an environment and wrote another one.
$ S = 'http: // www.abc.com/image/index.php "http://www.abc.com/images/logo.gif "';
Preg_match_all ('#/[^/] * (? <= \....(? Var_exp ......
Well, it makes sense that html images are all tagged, but there is also a case where the bbcode code is also tagged. can you help me write this complete expression? Let me give you an example,
[img=88,31]http://www.discuz.net/images/logo.gif[/img]
Match all url addresses except the above two cases. thank you !!!
Dizzy, you cannot edit the post. The first line of code above is actually from bbcode, that is, the second line is not = 88,31, and the Forum converts it to html.
In fact, you want to match the hyperlink address. just add href in front of it to match.
(? I )(? : Https? | Ftp): // [-a-z \ d.] + /? (?! /) ([-A-z \ d + & # % = ~ _ |! :,.;] + /)*(? # Remove the image URl )(?! [-A-z \ d + & # % = ~ _!,...]. *? \.(? : Jpg | jpeg | gif | png | bmp) [-a-z \ d + &#%= ~ _!,.;] *(? :\? [A-z \ d + & #/% = ~ _ |! :,.;] *)?