我正在使用这个雅虎管道正则表达式,我发现了一个我无法绕过它的错误。
我有一个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"/>
我怎样才能解析那些零点以使这个东西有效?
答案 0 :(得分:2)
如果你可以使用多个正则表达式,这里有一个解决方法:
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" />