I’m new to ruby and I’m trying to solve a problem.
I’m parsing through several text field where I want to remove the header which has different values. It works fine when the header always is the same:
variable = variable.gsub(/(^Header_1:$)/, '')
But when I put in several arguments it doesn’t work:
variable = variable.gsub(/(^Header_1$)/ || /(^Header_2$)/ || /(^Header_3$)/ || /(^Header_4$)/ || /^:$/, '')
You can use
Regexp.union:Please note that
^something$will not work on strings containing something more thansomething🙂Cause
^is for matching beginning of string and$is for end of string.So i intentionally removed
$.Also you do not need brackets when you only need to remove the matched string.
You can also use it like this:
And of course you can remove headers without explicitly define them.
Most likely there are a white space after headers?
If so, you can do it as simple as: