From: "Jesús Gabriel y Galán" Date: 2010-01-11T21:55:26+09:00 Subject: Re: Regex help On Mon, Jan 11, 2010 at 1:39 PM, Chris Lervag wrote: > Hi > I want to test a string for three properties: > 1) It is exactly 9 characters long. > 2) Character number 5 is a comma (','). > 3) The other characters are either numbers 0-9 or letters a-f. > > I have been able to do this by a combination of strings methods for 1) > and 2), and using a regex match on the string (stripped of the comma) > with the following code: > myString =~ /([^a-f0-9])/ > > If possible I would like to simplify this by using a more advanced regex > match to check all three properties at one time. If this is possible, > perhaps one of you regex wizards out there could show me how? :) irb(main):006:0> re = /\A[a-f0-9]{4},[a-f0-9]{4}\z/ => /\A[a-f0-9]{4},[a-f0-9]{4}\z/ irb(main):007:0> "abcd,4f2ddf" =~ re => nil irb(main):008:0> "abcd,4f32" =~ re => 0 Hope this helps, Jesus.