# RegEx Question

**URL:** <https://www.ruby-forum.com/t/regex-question/141460>\
**Category:** Ruby\
**Created:** [June 26, 2008, 1:08am UTC](https://www.ruby-forum.com/t/regex-question/141460 "2008-06-26T01:08:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 26, 2008, 1:08am UTC](https://www.ruby-forum.com/t/regex-question/141460/1 "2008-06-26T01:08:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 26, 2008, 1:23am UTC](https://www.ruby-forum.com/t/regex-question/141460/2 "2008-06-26T01:23:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 26, 2008, 2:38am UTC](https://www.ruby-forum.com/t/regex-question/141460/3 "2008-06-26T02:38:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 26, 2008, 2:48am UTC](https://www.ruby-forum.com/t/regex-question/141460/4 "2008-06-26T02:48:50Z")

</div>

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
