troubleshooting Question

Using REGEX to take the title attribute of a link and add the title attribute to an img tag as title and alt attributes

Avatar of wfninpa
wfninpa asked on
Regular Expressions
7 Comments1 Solution675 ViewsLast Modified:
I have the following code in hundreds of files that needs to be changed:

<div class="floatimg">
<a href="/catalogs/2010/images/JBL2110.jpg" rel="prettyPhoto" title="JBL Pro Speakers Model JBL2110">
<img src="/catalogs/2010/images/t/JBL2110.jpg" height="226" border="0"></a>
<p>JBL2110</p>
</div>

What I want to do using REGEX is take the contents of the "title" attribute from the "<a href" tag and insert it into the "<img" tag as "title" and "alt" attributes so that the end result will look like this:

<div class="floatimg">
<a href="/catalogs/2010/images/JBL2110.jpg" rel="prettyPhoto" title="JBL Pro Speakers Model JBL2110">
<img src="/catalogs/2010/images/t/JBL2110.jpg" height="226" border="0" title="JBL Pro Speakers Model JBL2110" alt="JBL Pro Speakers Model JBL2110"></a>
<p>JBL2110</p>
</div>

Obviously the REGEX needs to be flexible to handle incidental blank spaces, etc...  I've thrown my Regular Expression Pocket Reference on mu desk several times already and I'm starting to think the only way is to manually change all of them, which is not something I want to do.

It must be possible, REGEX is incredibly powerful.

Any help here?  I would ideally like to use Dreamweaver CS4, Crimson Editor, or Notepad++ to do my REGEX match, find, replace for me.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
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 7 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