Ruby正则表达式建议

时间:2014-03-24 00:14:59

标签: ruby-on-rails ruby regex

嗨,我有一个字符串,

<p style="margin:0pt; orphans:0; widows:0"><img src="asset/image/3/image.001.jpeg" width="333" height="166" alt="" data-np-asset-type="Image" data-np-asset-id="3" data-np-asset-target="src"/><p>some big paragraph</p>

我需要将图像src路径从 asset / image / 3 / image.001.jpeg 修改为 asset / image / 19 / image.001.jpeg 和< strong> data-np-asset-id =“3”到 data-np-asset-id =“19”

1 个答案:

答案 0 :(得分:0)

html = %{<span style="font-family:Verdana, sans-serif; font-size:1.08em; font-weight:bold">Birbal identifies the thief</span></p></td></tr><tr><td style="padding-left:5.4pt; padding-right:5.4pt; vertical-align:middle; width:382pt"><p style="margin:0pt; orphans:0; widows:0"><img src="asset/image/3/image.001.jpeg" width="333" height="166" alt="" data-np-asset-type="Image" data-np-asset-id="3" data-np-asset-target="src"/><p>some big paragraph</p>}

html.gsub!(/"3"/, "\"9\"").gsub!(/\/3\//, "/9/")
#=> "<span style=\"font-family:Verdana, sans-serif; font-size:1.08em; font-weight:bold\">Birbal identifies the thief</span></p></td></tr><tr><td style=\"padding-left:5.4pt; padding-right:5.4pt; vertical-align:middle; width:382pt\"><p style=\"margin:0pt; orphans:0; widows:0\"><img src=\"asset/image/9/image.001.jpeg\" width=\"333\" height=\"166\" alt=\"\" data-np-asset-type=\"Image\" data-np-asset-id=\"9\" data-np-asset-target=\"src\"/><p>some big paragraph</p>"