> 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