In this gsub block, I’d like to save the searched parenthetical data,
indicated by (.*) in line 2. The script works, but, instead of getting
the parenthetical data, I’m getting “$1.” Very literal, but, not what I
want. What am I doing wrong?
In this gsub block, I’d like to save the searched parenthetical data,
indicated by (.*) in line 2. The script works, but, instead of getting
the parenthetical data, I’m getting “$1.” Very literal, but, not what I
want. What am I doing wrong?
You’re missing a hash which leads to your $1 being used literally:
In this gsub block, I’d like to save the searched parenthetical data,
indicated by (.*) in line 2. The script works, but, instead of getting
the parenthetical data, I’m getting “$1.” Very literal, but, not what I
want. What am I doing wrong?
Also, the .* is gobbling up any digits except the last. You probably
want a space between .* and [0-9], or make the . match non-greedy with
.*?. Since your replacement string has a space, I’m guessing that’s
what you want.
– Jim W.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.