From: Robert Klemme Date: 2012-04-02T16:45:06+09:00 Subject: Re: regexp replace every other one gabe gabriellini wrote in post #1054415: > this works great: > > puts "abc def ghi jkl mno".gsub(/[a-z]{3}/, "123") > > The only problem i have is when i use a string like this one: > > puts "gabriel y martha iba gtz ibanez nat".gsub(/(\A|\s)([a-zA-Z]{3}) > ($|\s)/," Gutierrez ") > > the gtz after the iba does not get replaced I think you want \b (word boundary) to create something like this: irb(main):001:0> "gabriel y martha iba gtz ibanez nat".gsub /\b\w{3}\b/, 'X' => "gabriel y martha X X ibanez X" Kind regards robert -- Posted via http://www.ruby-forum.com/.