Ruby regex matching a line in an inputted text file string [duplicate]
This question already has answers here : Ruby regex gsub a line in a text file (5 answers) Closed 6 years ago . I need to match a line in an inputted text file string and wrap that captured line with a character for example. For example imagine a text file as such: test foo test bar I would like to use gsub to output: XtestX XfooX XtestX XbarX I'm having trouble matching a line though. I've tried using regex starting with ^ and ending with $, but it doesn't seem to work? Any ideas? I have a text file that has the following in it: test foo test bag The text file is being read in as a command