From: Intransition Date: 2010-01-30T12:56:57+09:00 Subject: Re: How do I use a variable in a regexp search string? On Jan 29, 10:38 pm, Harry Kakueki wrote: > > I dont know how to use a variable in a regex searchstring. > > ruby seems to only handle hardcoded serachstring in > > regex's.   How do you do this.   My code is below. > > Does this help? > > str = "abcdef" > searchstring = "cd" > p str =~ /#{searchstring}/ You may need to escape: p str =~ /#{Regexp.escape(searchstring)}/