正则表达式添加填充零

Man*_*ria 5 regex yahoo-pipes padding

我正在研究这个雅虎管道正则表达式,我发现了一个我无法绕过它的错误.

我有一个URL,我从中提取数字,捕捉它们并制作一个img html标签并嵌入它.问题是,URL以非填充方式显示,但链接的图像具有零.因此,当有一位数或一个月的单位数时,正则表达式将停止工作.

这是我到目前为止:

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"/>
Run Code Online (Sandbox Code Playgroud)

我怎么能解析这些零以使这个东西工作?

Sop*_*ert 2

如果您可以使用多个正则表达式,可以使用以下解决方法:

搜索:(\d{4})/(\d)/
替换:$1/0$2/
搜索:(\d{4})/(\d{2})/(\d)/
替换:$1/$2/0$3/
搜索:(\d{2})/(\d{2})/(\d{2})/(.+)/
替换: <img src="http://www.penny-arcade.com/images/$1/$2$3.jpg" />