RegEx Question

Hi, my practice program is suppose to read in versions like:

4.0
v4. 5
v 4.23

^each = p

t=“v”
p.gsub(/[^(v)]/i) {|m| t.concat(m)}

how do I, in the regEx, ignore white spaces?

I want the output to look like this:

v4.0
v4.5
v4.23

Thanks!

p.gsub(/[^(v| )]/i) {|m| t.concat(m)}

Oh, I got it… but now I’m stuck on how to remove ‘.’ if it’s the last
piece of the string

e.g. “v4.5.”

I want to remove the last “.”

Thanks

Justin To wrote:

p.gsub(/[^(v| )]/i) {|m| t.concat(m)}

Oh, I got it… but now I’m stuck on how to remove ‘.’ if it’s the last
piece of the string

e.g. “v4.5.”

I want to remove the last “.”

Thanks

“v4.5.”.gsub(/.$/,"")

Hi –

On Thu, 26 Jun 2008, Justin To wrote:

p.gsub(/[^(v| )]/i) {|m| t.concat(m)}

Oh, I got it… but now I’m stuck on how to remove ‘.’ if it’s the last
piece of the string

e.g. “v4.5.”

I want to remove the last “.”

If you’ve just got that string and want to remove the last ‘.’, as a
separate operation, you can do:

str.chomp!(’.’)

David