style_to_add
我想将str = "This website is <a href='www.google.com' style='text-decoration:none;>Google</a>, some other website is <a href='www.facebook.com' style='text-decoration:none;>Facebook</a>"
字符串添加到每个超链接。结果就变成了
{{1}}
答案 0 :(得分:0)
这个正则表达式将起作用
(href='[^']+')
将使用更准确的正则表达式
(\bhref='[>']+)>
Ruby代码
pattern = %r{(href='[^']+')}
str = "This website is <a href='www.google.com'>Google</a>, some other website is <a href='www.facebook.com'>Facebook</a>"
style_to_add = "style='text-decoration:none;'"
print str.gsub(pattern, '\1 ' + style_to_add)
<强> Ideone Demo 强>