From: Jeffrey Schwab Date: 2005-12-03T17:37:32+09:00 Subject: Re: Regex: except when basi wrote: > Hello, > I haven't grokked how to include an exception to a condition in a > regular expression. For example, I can't express this correctly: > > aString matches if it has a sequence of 3 or more consonants, except > when the consonants [ng] is in the sequence (in that order, n followed > by g). > > Thus: plants will match, but bangking will not match. You might find negative look-ahead helpful. For example: consonant = '[bcdfghjklmnpqrstvwxyz]' r = /#{consonant}{3,}(?!.*ng)/ print "plants: ", r =~ "plants", "\n" print "bangking: ", r =~ "bangking", "\n"