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!

···

--
Posted via http://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/.

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(/\.$/,"")

···

--
Posted via http://www.ruby-forum.com/\.

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

--
Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS June 16-19 Berlin
   ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.rubypal.com for details and updates!