Title |
Test
Find
Pattern Title
|
Expression |
(?:[\w]*) *= *"(?:(?:(?:(?:(?:\\\W)*\\\W)*[^"]*)\\\W)*[^"]*") |
Description |
This Pattern matches HTML attributes with quoted quotes or other non-word characters correctly. I used it in an parser-engine.
Replace the quotes in this RX to match other boundaries. |
Matches |
<HTMLTAG onClick="jsfunc(\"foo\")"> |
Non-Matches |
<HTMLTAG onClick sometext> |
Author |
Rating:
Lars Echterhoff
|
Source |
|
Your Rating |
|
Title: Slight extension
Name: Matthew D Erwin
Date: 5/1/2008 2:42:53 PM
Comment:
An extension onto this to handle attribute cases with or without quotes (could be made more robust on the \w and I'm sure compressed a bit):
[\s\t]+\w[\s\t]*=[\s\t]*((\"((?:(?:(?:(?:(?:\\\W)*\\\W)*[^"]*)\\\W)*)[^\">]*))|((?:(?:(?:(?:(?:\\\W)*\\\W)*[^"]*)\\\W)*)[^\"\s\t/>]*))
Works well for extracting even poorly formed attributes inluding cases like:
<img src="some value/>
<img src=something/>
<img src="someting \"with escaped items\"\s"/>
Hope this is helpful to someone.
Title: ty
Name: Moe
Date: 11/6/2006 6:12:23 AM
Comment:
Works great, ty.
Title: Thanks - you saved my sanity
Name: Greg
Date: 6/29/2006 6:05:06 PM
Comment:
Thanks for posting this. You saved me hours of confusion. Good job.