From: Patrick Hurley Date: 2005-03-24T11:50:47+09:00 Subject: Re: (Maybe) a simple question about regex What they said, but also if you can be more precise about your real problem, we might be able to better model a solution. You might find matching the expression you want and then scanning it to be more flexible for example. On Thu, 24 Mar 2005 11:09:51 +0900, Assaph Mehr wrote: > > > s = '0123456789' > > s.scan(/\d\d/) #-> ["01", "23", "45", "67", "89"] > > > > Now I want to exclude "45". > > How can I express it in the regex? > > When it's only one character, I can use ^. > > But for 2 characters, I don't think I can use it. > > > > What I want is: > > > > s = '0123456789' > > s.scan(some_regex) #-> ["01", "23", "67", "89"] > > Negative lookahead: > s.scan /(?!4|5)\d\d/ > Note the OR sign ('|') between the digits, otherwise it would produce: > ["01", "23", "56", "78"] > > You need to tune it to your exact domain. > > Cheers, > Assaph > >