4
我正在這個雅虎管道上正則表達式和我發現了一個錯誤,我無法把我的思想包圍它。正則表達式來添加填充零
我有一個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"/>
我怎麼能解析那些零,以使這件事情的工作?
刪除了我的答案,因爲我完全把你當成.NET-ING它。我的錯。 – Will 2009-01-02 23:56:40