问题描述
使用红宝石gsub()
,将字符串<code>balabala or blank \n another balabala or blank</code>
中的\n
内的所有<code>...</code>
替换为<br>
,但对{{1 }}。
我尝试了<code>...</code>
,但是没有用:
/<code>.*(\\n?).*<\/code>/
解决方法
匹配<code>
和</code>
之间的所有子字符串,并仅在那些匹配项中将所有\n
替换为<br>
:
html = html.gsub(/<code>.*?<\/code>/m) { $~[0].gsub('\n','<br>') }