From: Joseph Pecoraro Date: 2008-01-26T11:35:48+09:00 Subject: Re: regular expression negate a word (not character) SpringFlowers AutumnMoon wrote: > On Jan 25, 5:16 pm, Summercool wrote: >> >> snowtire > > i could think of something like > > /[^s][^n][^o][^w]\s*tire/i > > but what if it is not snow but some 20 character-word, then do we need > to do it 20 times to negate it? any shorter way? I took a long look at this and I came up with a number of different methods, including an idea like the one you have above. If you have a set number of bad/undesirable words then everything falls apart. I tried negative look behinds but those don't work well with 0 or more spaces because look-behinds have to have a fixed length. I really don't think that this could be done elegantly with a single regular expression if you have multiple bad/undesirable words. However, if you split this into two regular expressions then it becomes rather straightforward. I really have spent the last 20 minutes trying out different possibilities with a single regular expressions but it just doesn't seem worth the difficulty =( May I ask why there is the requirement for a single regular expression? - Joe P -- Posted via http://www.ruby-forum.com/.