Find the regular expression for filtering alt

Source: Internet
Author: User
Regular expression for filtering alt

Obtain the regular expression for filtering alt in PHP. alt can be filtered out in three cases.
Alt = "xxxxxxxxxxxx"
Alt = 'xxxxxxxxxxxxxxxx'
Alt = xxxxxxxxxxxx

You must be able to filter out the above three cases.


Example:







......



It is required to filter various situations without filtering other content. Thank you.


Reply to discussion (solution)

$s =<<< TXTTXT;echo preg_replace('/alt=([\'"]?).+?\b\1/is', '', $s);





Obtain the regular expression for filtering alt in PHP. alt can be filtered out in three cases.
Alt = "xxxxxxxxxxxx"
Alt = 'xxxxxxxxxxxxxxxx'
Alt = xxxxxxxxxxxx

You must be able to filter out the above three cases.


Example:







......



It is required to filter various situations without filtering other content. Thank you.
$ Str ='



';
Echo preg_replace ('/(. *) (alt = [\ "\']?. *? [\ "\ ']? \ S +) (. *)/',' $1 $ 3', $ str );

$s =<<< TXTTXT;echo preg_replace('/alt=([\'"]?).+?\b\1/is', '', $s);







The method you provided may only be suitable for the example I wrote above. I will give the actual content and I will know that there is a problem with filtering.

       

         



Obtain the regular expression for filtering alt in PHP. alt can be filtered out in three cases.
Alt = "xxxxxxxxxxxx"
Alt = 'xxxxxxxxxxxxxxxx'
Alt = xxxxxxxxxxxx

You must be able to filter out the above three cases.


Example:







......



It is required to filter various situations without filtering other content. Thank you.
$ Str ='



';
Echo preg_replace ('/(. *) (alt = [\ "\']?. *? [\ "\ ']? \ S +) (. *)/',' $1 $ 3', $ str );

The method you provided may only be suitable for the example I wrote above. I will give the actual content and I will know that there is a problem with filtering.

       

         

I know that I have a problem with the regular expression. adding that \ B is a last resort.
However, since the data in your example can be satisfied, you can.
You can't let me list the possible situations? What are you doing?

$s =<<< TXT



TXT;echo preg_replace('/alt=([\'"]?).+?\1(\s|>)/is', '$2', $s);















Obtain the regular expression for filtering alt in PHP. alt can be filtered out in three cases.
Alt = "xxxxxxxxxxxx"
Alt = 'xxxxxxxxxxxxxxxx'
Alt = xxxxxxxxxxxx

You must be able to filter out the above three cases.


Example:







......



It is required to filter various situations without filtering other content. Thank you.
$ Str ='



';
Echo preg_replace ('/(. *) (alt = [\ "\']?. *? [\ "\ ']? \ S +) (. *)/',' $1 $ 3', $ str );

The method you provided may only be suitable for the example I wrote above. I will give the actual content and I will know that there is a problem with filtering.

       

         


Are you sure you want to test me?

$ Str = <TXT













TXT;
Echo preg_replace ('/(.*?) (Alt = ["\ ']?. *? ["\ ']?) (\ S + |>)/',' $1 $ 3', $ str );
I forgot to lean on the situation where there is no space at the end. I can add the case where there is no space at the end.

Thank you very much!

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.