Is there a regular expression that matches the url but does not match the image?

Source: Internet
Author: User
Tags bbcode
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 + & #/% = ~ _ |! :,.;] *)?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.