How to deal with a regular expression that matches all <img> tags

Source: Internet
Author: User
You want a regular expression that matches all & lt; img & gt; tags and a regular expression that matches all & lt; img & gt; tags, in addition, the SRC attribute in this tag cannot contain the word logo, and the word does not match. Thank you. ------ Solution ------------------ PHPcode & lt; pre & gt; & lt ;? Php $ string & quot; adsfasdfa & lt; I wants a regular expression that matches all tags
If you want a regular expression that matches all tags, and the SRC attribute in the Tag cannot contain the word logo, the word does not match.
Thank you.

------ Solution --------------------
PHP code
   

------ Solution --------------------


(?! -Characters after negative pre-check
.*? Greedy match all data before logo
(?!. *? Logo)-indicates matching all logos not included
. *> It is matched before all line breaks>-this is not used here .*? Greedy mainly to avoid the occurrence of> characters in the middle of alt = "abc>"

However, there will be a special case above.

For example

Alt prompt containing logo
Custom attributes


If you consider these situations, you can refine the regular expression to the src position.


------ Solution --------------------
Discussion


(?! -Characters after negative pre-check
.*? Greedy match all data before logo
(?!. *? Logo)-indicates matching all logos not included
. *> It is matched before all line breaks>-this is not used here .*? Greedy mainly to avoid the occurrence of> characters in the middle of alt = "abc>"

However, there will be a special case above.

For example

Alt prompt containing logo
Custom attributes


If you consider these situations, you can refine the regular expression to the src position.


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.