Is it possible to use negative matches within gsub expressions? I want to replace strings starting by hello except those starting by hello Pe
hello
hello Pe
Sounds like you want a negative lookahead:
>> "hello foo".gsub(/hello (?!peter)/, 'lala ') #=> "lala foo" >> "hello peter".gsub(/hello (?!peter)/, 'lala ') #=> "hello peter"