I'm trying to remove a pattern from a string using the ruby gsub
method. Given the following string:
ANTONIO JUAREZ HAMPEL SCHLICH-
TING
I need to remove only the hyphen at end of line and turn the string into a single line, like ANTONIO JUAREZ HAMPEL SCHLICHTING
. I tried:
name = <<-TEXT
ANTONIO JUAREZ HAMPEL SCHLICH-
TING
TEXT
name.gsub(/[a-zA-Z](\-\n)/, '')
But it don't worked. The gsub should remove ONLY the (\-\n)
immediately after any non-numeric character ([a-zA-Z]
).
Searching here, at SO, I figured out through this question that gsub
ignore the regexp group and do the substitution for all the pattern. Are there an option to gsub in ruby, or a different way on using this method that I can achieve this result?