在我的 Rails 应用程序中,我将问题保存为 html。例如,
"<p><pre dir=\"ltr\" style=\"background-color: #ede7db; color:
#000000; margin: 0px; padding: 6px; border: 1px inset; width: 640px; height: 194px; text-align: left; overflow: auto; background-position: initial initial; background-repeat: initial initial;\" class=\"alt2\">void myFunc (int x) <br />{ <br /> if (x &gt; 0)<br /> myFunc(--x); <br /> printf(\"%d, \", x); <br />} <br />int main() <br />{ <br /> myFunc(5); <br /> return 0; <br />}</pre></p>"
我需要将所有宽度属性替换为 width:auto;
帮我做同样的事情。谢谢:)-
最佳答案
试试这个,假设字符串位于变量 s
中:
s.gsub(/width:[^;]*;/, 'width: auto;')
关于ruby-on-rails - 将子字符串替换为另一个字符串 rails ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15090240/