From: Ammar Ali Date: 2012-04-01T05:26:49+09:00 Subject: Re: regexp replace every other one On Sat, Mar 31, 2012 at 11:09 PM, gabe gabriellini wrote: > thank you Ammar You're welcome! > 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 This is the same problem i mentioned. The pattern matches: - the beginning of line (\A) or a space (\s) - followed by 3 alphabet characters ([a-zA-Z]{3}) - followed by end of line ($) or a space (\s) When this matches iba, it matchs " iba " (that is space iba space). When it gets to the gtz part, it doesn't match because it needs to match a beginning of a line (\A) or a space (\s) again, but these space before it has already been matched. So it fails. To help in understanding this, add an extra space between the ibz and gtz. Then it will work. Good luck, Ammar