RegEx Question

J

Justin To

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!
 
J

Justin To

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
 
R

Rodrigo Bermejo

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

David A. Black

Hi --

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top