Is there a matching URL but a regular expression other than the picture?

Source: Internet
Author: User
Tags bbcode
For example, http://www.abc.com/and http://www.abc.com/images/index.php can all match,
But Http://www.abc.com/images/logo.gif can't match.
The expression I wrote will match to Http://www.abc.com/images/logo. This paragraph
(http\://)? ([a-z0-9_-]+\.) + (com|net|cn|org) {1} (\/[a-z0-9_-]+) *\.? (?! Jpg|jpeg|gif|png|bmp)


Reply to discussion (solution)

The general URL is followed by other unrelated characters, and it is recommended that you use this character
For example:
"Http://www.abc.com/images/logo.gif"
... Before (?!:jpg|jpeg|gif|png|bmp) (?: ")

Just did not test environment, feel free to write, think of a bit of a problem, find an environment to re-write a

$s = ' http://www.abc.com/image/index.php ' http://www.abc.com/images/logo.gif ';
Preg_match_all (' #/[^/]* (? <=\ .... (? Var_export ($m);

In general, you can understand it and then change it.
Here \ .... Matches the dot and three-character extensions, without a dot extension or a three-character case.

Just did not test environment, feel free to write, think of a bit of a problem, find an environment to re-write a

$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 pictures are tagged, but there is a situation where the code is BBCode, and fortunately it is 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 the URL addresses except the above two cases, thank you!!!

Halo, can not edit the post, the first line of code is actually BBCode, is the second line without =88,31 this paragraph, the forum to turn it into HTML

In fact, you want to match the hyperlink address, the front plus the href is good match.

(? i) (?: https?| FTP)://[-a-z\d.] +/? (?! /) ([-a-z\d+&@#%=~_|!:,.;] +/) * (? #去掉图片的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.