From: Robert Klemme Date: 2004-01-11T23:01:39+09:00 Subject: Re: regex to NOT match? "Alexander Kellett" schrieb im Newsbeitrag news:200401102209.22341.ruby-lists@lypanov.net... > On Saturday 10 January 2004 21:57, Ruby Baby wrote: > > Sorry it seems like the smallest thing, but I'm stuck on this. > > > > I'm trying to make a simple regex to strip away characters that are NOT > > certain characters I name. I'm unclear on what Ruby uses as a "NOT" match > > in regex, like ! is for != (Or if it uses the ^, where does it put it?) > > > > EXAMPLE: > > > > myString = 'I want only the letters a and t and period. When done it > > should look like atttaatta.tatttaatta..' > > > > # this doesn't work of course: > > puts myString.gsub(!/at\./, '') > > puts myString.gsub(/[^at.]/,'') This is likely a bit more efficient since it does less replacement operations: myString.gsub!( /[^at.]+/, '' ) Regards robert