Here’s how to identify a keyword in a block of text using a case-insensitive regular expression, and surround that keyword with an HTML tag:
text = "hello world, this is a test" text.gsub!(/(WORLD)/i, "\1")
The following string is produced:
hello world, this is a test
\1 references the group in the regex (surrounded by parens). This results in the original value being placed within the HTML tags, instead of the uppercased WORLD in the regex.