[英]Replace substring with another string rails
在我的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;')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.