Question

I have a lot of URLs like this one

<a href="http://abc123.linkbucks.com"><img src="http://img187.imagevenue.com/loc1115/th_99189_image_122_1115lo.jpg" /></a>

I need to substitute the href part whith the img src part, so it would say

<a href="http://img187.imagevenue.com/loc1115/th_99189_image_122_1115lo.jpg"><img src="http://img187.imagevenue.com/loc1115/th_99189_image_122_1115lo.jpg" /></a>

and then replace the loc???/th_ part with img.php?image= so it would be

<a href="http://img187.imagevenue.com/img.php?image=99189_image_122_1115lo.jpg"><img src="http://img187.imagevenue.com/loc1115/th_99189_image_122_1115lo.jpg" /></a>

Can anyone help me do this with TextWrangler for Mac? The linkbucks links and loc and img bits are all random. I've tried searching but the solutions seem to be very specific and my understanding of regex is so scarce... Thank you!

Was it helpful?

Solution

Edit:

I don't know TextWrangler but I could imagine that following might work:

# 1st step:
search expression: (<a href=")[^"]*("><img src=")([^"]*)"
replacement:       \1\3\2\3"

# 2nd step:
search expression: (<a href="[^"]*)/loc[^/]*/th_
replacement:       \1/img.php?image=
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top