All that escaping in the Regexp.new
is looking quite ugly. You could greatly simplify that by using a Regexp literal:
word = 'below'
text = "I said, 'look out below'"
reg = /#{word}/i
text.gsub!(reg, '<b></b>')
Also, you could use the modifier form of gsub!
directly, unless that string is aliased in some other place in your code that you are not showing us. Lastly, if you use the single quoted string literal inside your gsub
call, you don't need to escape the backslash.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…