From: Stefano Crocco Date: 2008-08-26T16:38:00+09:00 Subject: Re: word boundaries for regular expressions On Tuesday 26 August 2008, Adam Akhtar wrote: > Hi did a search for word boundaries but didnt quite find what i was > looking for. > > If i have strings containing products and model numbers > > e.g. > "JP-ATH Headphones JP" > > and I want to remove the last JP but not the one in the modle number how > do i go about it, > > i tried > > string.gsub(/\bJP\b/, '') > but it removes both. > I guess the hypen in the model number doesnt count as a word letter so > it gets knocked off. > > am i doing something wrong here? You can replace the first \b with \s, which only matches spaces: string.gsub(/\sJP\b/, '') I hope this helps Stefano