troubleshooting Question

Prefix/Suffix stuff to href elemenst using Regex

Avatar of debuchakrabarty
debuchakrabarty asked on
Java
3 Comments1 Solution770 ViewsLast Modified:
Hi,

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="http://google.com">Google</a> should become <a href="javascript:myJSFunction('http://google.com')">Google</a>, again I have to take care of scenario where User types the URL as <a href='http://google.com'>Google</a> or <a href=http://google.com>Google</a>.

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

Thanks for your time and help,

Debashish
ASKER CERTIFIED SOLUTION
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