KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is is possible to create/use a regular expression pattern in ruby that is based on the value of a variable name? For instance, we all know we can do the following with Ruby strings: str = "my string" str2 = "This is #{str}" # => "This is my string" I'd like to do the same thing with regular expressions: var = "Value" str = "a test Value" str.gsub( /#{var}/, 'foo' ) # => "a test foo" Obviously that doesn't work as listed, I only put it there as an example to show what I'd like to do. I need to regexp match based on the value of a variable's content.
Tags (comma-separated)
Save Edits
Cancel