pattern = %r{(href='[^']+')} str = "This website is Google, some other website is Facebook" style_to_add = "style='text-decoration:none;'" print str.gsub(pattern, '\1 ' + style_to_add)