# RegEx

**URL:** <https://www.ruby-forum.com/t/regex/141953>\
**Category:** Ruby\
**Created:** [July 2, 2008, 12:21am UTC](https://www.ruby-forum.com/t/regex/141953 "2008-07-02T00:21:33Z")\
**Posts on this page:** 3\
**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:** [July 2, 2008, 12:21am UTC](https://www.ruby-forum.com/t/regex/141953/1 "2008-07-02T00:21:33Z")

</div>

version:

1. abc 600-qwer
2. abc600-qwer
3. abc 6.0.0-pedfs
4. abc 6.12.23-45
5. abc 5.0.6.0  
etc…

I want to be able to identify which version is version 6, version 5,  
etc…

I’m not sure if a regex is the best way. I need to be able to say that  
#1-4 are version 6 and #5 is version 5. But I need to be able to  
identify versions 1-8. Also, what if I need to identify, specifically,  
version 5.5 and 5.6?

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:** [July 2, 2008, 7:25am UTC](https://www.ruby-forum.com/t/regex/141953/2 "2008-07-02T07:25:24Z")

</div>

On Jul 2, 12:09 am, yermej [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > etc…
> 
> > I want to be able to identify which version is version 6, version 5,  
> > etc…
> 
> > I’m not sure if a regex is the best way. I need to be able to say that  
> > #1-4 are version 6 and #5 is version 5. But I need to be able to  
> > identify versions 1-8. Also, what if I need to identify, specifically,  
> > version 5.5 and 5.6?

Sorry about that. Firefox decided it was time to update and then  
posted what I had already typed.

str = [‘abc 600-qwer’, ‘abc600-qwer’, ‘abc 6.0.0-pedfs’, ‘abc  
6.12.23-45’, ‘abc 5.0.6.0’]

versions = str.map {|v| v.gsub(/\D/, ‘’)[0,1]}  
=\> [“6”, “6”, “6”, “6”, “5”]  
That will get you the major version numbers. If you want minors, etc.,  
you’ll need a more specific format, I think. Otherwise, you couldn’t  
be sure that ‘abc 600-qwer’ is version 6, 60, or 600. If you assume  
the major is a single digit:

str.map {|v| v.scan(/(\d).?(\d+)/)[0]}  
=\> [[“6”, “00”], [“6”, “00”], [“6”, “0”], [“6”, “12”], [“5”, “0”]]

If you know more specifics about the version format, you could get  
better results; particularly if you need anything beyond the minor  
number.

---

<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:** [July 2, 2008, 7:10am UTC](https://www.ruby-forum.com/t/regex/141953/3 "2008-07-02T07:10:46Z")

</div>

On Jul 1, 5:18 pm, Justin To [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m not sure if a regex is the best way. I need to be able to say that  
> #1-4 are version 6 and #5 is version 5. But I need to be able to  
> identify versions 1-8. Also, what if I need to identify, specifically,  
> version 5.5 and 5.6?
> 
> ## Thanks
> 
> Posted viahttp://www.ruby-forum.com/.

str = [‘abc 600-qwer’, ‘abc600-qwer’, ‘abc 6.0.0-pedfs’, 'ab
