RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 3
Title Test Details IMG tag
Expression
<img[^>]*src=\"?([^\"]*)\"?([^>]*alt=\"?([^\"]*)\"?)?[^>]*>
Description
Use this RegExp to grab SRC($1) and ALT($3) values from IMG tags in valid or invalid HTML (XHTML). SRC param must by before IMG. (thanks to mr. Mrva)
Matches
&lt;img src="xxx"&gt; | &lt;img src=xxx&gt; | &lt;img src="xxx" alt="xxx" /&gt; | &lt;img src="xxx" alt="xxx" width="N" height="N" /&gt; | etc.
Non-Matches
&lt;img&gt; | &lt;img /&gt; | &lt;img alt="XXX" src="XXX"&gt;
Author Rating: The rating for this expression. Martin Švec
Title Test Details (X)HTML & char. replace
Expression
&(?![a-z]+;|#\d+;)
Description
Single & character is not valid in HTML or XHTML code. In this case you can replace this character with its entity (if & character is not member of other entity [&amp;#353;]). example: preg_replace('/&(?!amp;)/', '&amp;amp;', $str). (thanks to mr. Mrva)
Matches
&
Non-Matches
&amp;amp;|&amp;quot;|&amp;#353;|&blah;|&amp;copy;
Author Rating: Not yet rated. Martin Švec
   Displaying page 1 of 1 pages; Items 1 to 3

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials