Parsing anchor tags in HTML w/ certain attributes and replacing w/ new attributes

Micah

Newcomer
Joined
Mar 7, 2005
Messages
5
Hello all.

i am having this problem. i have got to correct a whole site worth of links. i want to basically check them to see if they have the title attribute and do not contain onMouse[XXX] events and replace the attributes with an added mouse events that will contain JS statements to change the status bar to what was in the title attribute. i hope this makes sense.

here is an example

<a href="www.somewhere.com" title="Click me now, please." class="something" >

i would want the expression to evaluate to this

<a href="www.somewhere.com" title="Click me now, please." class="something" onMouseOver="window.status='Click me now, please.';return true;" onMouseOut="window.status='';return true;">

Is this even possible?? i have played with it a bit, but honestly i was not even sure if it was possible :confused: . i am hoping someone can help please.

thanks in advance!
 
here's some stuff that will help.

find the title
title=(?<!\\)(\\\\)*"(?<title>.*?)(?<!\\)(\\\\)*"

find the onmouseXXX
(?<onName>onMouse[^=]+)=(?<!\\)(\\\\)*"(?<onAction>.*?)(?<!\\)(\\\\)*"

you'll need a regex to find the anchors, I didn't make one because I don't know if you have nested anchors, we'll here's a simple one.

(?i)(<a.*?>)|(<a>.*?</a>)

I think you'll also find the MatchEvaluator delegate useful.
 
thanks for the reply. that is a great use of neg lookbehinds.

that is a great basis for me to work with.

do you know if there is a way for me to combine them into one exression with conditional expressions??

-Micah
 
I would, but the problem is, I don't know if the title will always come before the onmouseXXX, and vice versa. To do it in 1 regex, I would combine the two regexes using the |
(regexA regexB)|(regexB regexA)
 
Back
Top