Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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.

Posted

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

Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...