I don't have the original question you asked, and I'm not sure you specified
what the rules should be. Neither do I have the original Regular Expression
I posted for you. The one you posted is modified. So, I can't tell you what
rules I assumed for those which were not provided, nor can I tell you
whether the change you made to the regular expression has anything to do
with it.
Therefore, I went back into my personal library, and found a Regular
Expression I once created for another project, which identifies all
attribute names and values (in 2 groups) in a block of HTML text. The
original was this, to capture *all* attribute names and values:
(?i)\s+(?:(\w+)=(?:["']?([^"'>=]*)["']?)(?=\s|/?>)|\s*(?=\s|/?>))
The first group is defined by the sequence: (\w+) (any sequence of one or
more alpha-numeric characters).
I replaced that with the following:
(?i)\s+(?:(onclick)=(?:["']?([^"'>=]*)["']?)(?=\s|/?>)|\s*(?=\s|/?>))
This will only capture attributes with a name of "onclick"
(case-insensitive)
Upon testing it with your script sample below, it correctly identified only
ONE of the attributes, the first one. The reason it didn't identify the
second one you said that it should is that the second one is not correct
syntactically. In HTML, the '=' character in an attribute may not be
preceded or followed by any spaces.
--
HTH,
Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com
Parabola is a mate of plane.
"Shawn B." <le****@html.comwrote in message
news:uZ**************@TK2MSFTNGP06.phx.gbl...
>(?i)(?<=<[\w]+[^<\>=]+)(onclick)=(?:["']?([^"'>=]*)["']?)
This regular expression will capture the entire attribute name and value.
The name ("onmouseover" will be in Group 1, and the value in Group 2.
Using Regulator, the above expression does not work on the following test
cases:
<SCRIPT NAME=Happy VALUE='happier' ATTR="happiest"
onClick='dosomething();'>CONENT</SCRIPT>
<SCRIPT name=ha onclick = 'asdf'>asdf</SCRIPT>
<tag>var x = asdf.onclick="";</tag>
It should detect #1 and #2 but ignore #3
Thanks,
Shawn