troubleshooting Question

Prefix/Suffix stuff to href elemenst using Regex

Avatar of debuchakrabarty
debuchakrabarty asked on
3 Comments1 Solution770 ViewsLast Modified:

I am looking for a help regarding using Java Regex.

My requirement is to convert all "href"s in an HTML chunk so as to prefix and suffix some stuff on it. For example: <a href="">Google</a> should become <a href="javascript:myJSFunction('')">Google</a>, again I have to take care of scenario where User types the URL as <a href=''>Google</a> or <a href=>Google</a>.

The tricky part is that I only want href elements to be converted so <a href=""><img src=""></a> should also get converted to <a href="javascript:myJSFunction('')"><img src=""></a>, meaning the pattern shouldn't just look for all occurances of http:// only.

Thanks for your time and help,

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros