5

I am working on this yahoo pipe Regex and I found a bug I'm unable to wrap my mind around it.

I have a URL, from which I extract digits, cat them and make a img html tag and embed it. The issue is that, the URL is presented in a non padded way, but the image linked has the zeroes. Therefore, when there is a day or a month with single digits, the regex stops working.

This is what I have so far:

The URL: http://www.penny-arcade.com/comic/2009/1/2/patently-ridiculous/
The RegEx: (\d{4})/(\d+)/(\d+)
The Replacement: <img src="http://www.penny-arcade.com/images/$1/$1$2$3.jpg" />

What should appear: <img src="http://www.penny-arcade.com/images/2009/20090102.jpg" />
What appears: <img src="http://www.penny-arcade.com/images/2009/200912.jpg"/>

How could I parse those zeroes as to make this thing work?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Manuel Ferreria
  • 1,216
  • 1
  • 13
  • 23
  • Deleted my answer as I completely assumed you were .net-ing it. My bad. –  Jan 02 '09 at 23:56

1 Answers1

2

If you can use more than one regular expression, here's a workaround:

search: (\d{4})/(\d)/
replace: $1/0$2/
search: (\d{4})/(\d{2})/(\d)/
replace: $1/$2/0$3/
search: (\d{2})/(\d{2})/(\d{2})/(.+)/
replace: <img src="http://www.penny-arcade.com/images/$1/$2$3.jpg" />
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238