views:

1049

answers:

1

my question is similar to the one here:

http://stackoverflow.com/questions/360492/regular-expression-on-yahoo-pipes

i have my gmail status hooked up to twitter through friendfeed, but unfortunately, they truncate the link text, and my links aren't working once they get to twitter. I need to be able to take this:

 <div style="margin-top:2px;color:black;">/good jquery tips 
   <a rel="nofollow" style="text-decoration:none;color:#00c;" target="_blank"  href="http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/" title="http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/"&gt;
      http://james.padolsey.com/javascr...
   </a>
</div> 

and replace the truncated link with the href attribute, so it looks like this:

 <div style="margin-top:2px;color:black;">/good jquery tips 
   <a rel="nofollow" style="text-decoration:none;color:#00c;" target="_blank"  href="http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/" title="http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/"&gt;
      http://james.padolsey.com/javascript/things-you-may-not-know-about-jquery/
   </a>
</div> 

thanks for the help!

A: 

Anthony's warning stands, you can't parse HTML safely with regexes, so please weigh up the risks involved if you choose to use Pipes.

Assuming you want to replace only this specific structure, and expect it to break if anything in the source changes subtly, the following will work well enough for your purposes:

replace:

(<a\s[^>]*href=")(.*?)("[^>]*>).*?(</a>)

with:

$1$2$3$2$4

(Using s and i options)

Gavin Brock