RegEx

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

On Jul 2, 12:09 am, yermej [email protected] 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.

On Jul 1, 5:18 pm, Justin To [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs