Replace your word with _the_pattern_
. Here .*
means any character.
s.gsub(/.*(_the_pattern_).*/, '\1')
Make sure the word doesn't contain any special regex characters like ( [ + *
etc.
s.gsub(/.*(ipsum dolor).*/, '\1')
\1
is the captured group in ()
from regex matching.