On 17.06.2008 18:08, Justin To wrote:
> Hello! I'm trying this problem that says I must match versions in a CSV
> file,
> 
> could be anything like:
> 
> v.6.0.3-3
> aajd4-43_3
> ABCD 5.0
> ABCDv.5.0
> A 3.40
> ..
> 
> With the other fields in mind, I thought "heck, looks like versions are
> the only ones that contain a series of letters, digits, periods,
> underscores and dashes..."
> 
> I'm pretty new to Ruby so I don't have very much experience with regular
> expressions. Is it possible to make just one regular expression to
> fulfill my problem? I need a regular expression that will return:
> 
> v.6.0.3-3: true because there's a v followed by a series of '.' and
> digits
> aajd4-43_3: true because there's a series of digits, '-', and '_'
> ABCD 5.0: true because there's a series of digits and '.'
> ABCDv.5.0: true...
> A 3.40: true...
> 
> Thanks for the help!

Yes, that's easy, just /./ as an expression.

Seriously, it is similarly crucial what it does *not* match.

The easiest (but not most efficient approach) would be to create on 
alternative for each variant you have, like

%r{
   ^(?:
     v(?:\.\d+)+-\d+
   | \w+\d+-[\d_]+
   | ...
   )$
}x

etc.

But given the number of alternatives you present it might be difficult 
to avoid also matching other stuff.  At least, you'll face a pretty 
complex regular expression.

Kind regards

	robert