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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
<[a-zA-Z]+(\s+[a-zA-Z]+\s*=\s*("([^"]*)"|'([^']*)'))*\s*/>
Description
Matches a valid &quot;empty&quot; tag (has trailing slash). Note, if you run it against a string such as &lt;img src=&quot;test.gif&quot; alt=&quot;&lt;hr /&gt;&quot;&gt; it will indeed return a match. But, the match is not at character 1 like you'd suspect, but rather it's matching the internal &lt;hr /&gt;. If you look at the source of this tag (http://concepts.waetech.com/unclosed_tags/) you'll find a whoe suite of regex's for matching html tags. Using them you could feasibly step though a document and avoid this mismatch as the outer tag would match *in totality* and you'd completely skip this inner match.
Matches
<img src="test.gif"/>
Non-Matches
<img src="test.gif"> | <img src="test.gif"a/>
Author Rating: Not yet rated. Joshua Olson
Source http://concepts.waetech.com/unclosed_tags/
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Non-Greedy?
Name: awc
Date: 12/5/2008 3:56:00 PM
Comment:
After the [^"]* and [^']*, shouldn't there be a ? to make it non-greedy? Without the question mark, it'll eat up an entire page of HTML! Correct me if I'm wrong...


Title: No parse error for me
Name: Darren Neimke
Date: 4/29/2004 3:27:56 AM
Comment:
I just copied and pasted this expression into The Regulator and it parsed just fine. You can also click "test" to go and test it for yourself on this site's Testing tool.


Title: parse error
Name: parse error
Date: 4/28/2004 6:48:41 AM
Comment:
this expr gives parse error!!!!!!!!!!!!


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