2

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!

lisa
  • 23
  • 2

1 Answers1

1

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=
bmk
  • 13,849
  • 5
  • 37
  • 46
  • thank you very much, unfortunately I made a mistake :( I should've mad it clear that the tool I use is a text editor named TextWrangler [link](http://www.barebones.com/products/textwrangler/)[/link] I have to enter one string it should find and one string it would replace the found string with. – lisa May 23 '11 at 15:04
  • @lisa: Sorry - I understand the question wrong. I suggest you another solution which might work - if not I will delete my answer. – bmk May 23 '11 at 15:25
  • Wow, thank you! The first step works great! But the seconds replaces both instances of loc???/th_, I only need it replaced in the href bit, the img src should remain unchanged... – lisa May 23 '11 at 15:29
  • OK - I understand. I used a behavior of `sed` which only substitutes the first occurrence in a line except when you explicitly specify a global replace (`g`). I will update the answer. – bmk May 23 '11 at 15:35