lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, 11 Jan 2002, Enrico Colombini wrote:

> I have to change a whole word (s) with another word (sh) in a string
> (line), using gsub, but I can't find a simple way to do it.
>
> Suppose the first word (s) is "the"; I want to change every occurrence of
> "the" but not to change the "the" in "theory", "atheist" or "lithe".

Another solution is like this:

  line = ' '..line..' '
  line = gsub(line, '(%W)'..s..'(%W)', '%1'..sh..'%2') -- in the middle
  line = strsub(line, 2, -2)

-- Roberto