From: Radek Hnilica Date: 2002-12-19T18:33:56+09:00 Subject: Re: Few question about IO On Thu, Dec 19, 2002 at 05:41:46PM +0900, Greg Millam wrote: > On Thu, 19 Dec 2002, Radek Hnilica wrote: > > \s is all white space characters, and \S is all non-whitespace characters. > since you also wish to match end of line, this might work: > > s.gsub(%r[(\s|^)#{word}(\s|$)],%Q[\1#{id}\2]) > > This has one flaw: > > s = "foo foo foo foo" > word = "foo" > id = "bar" > > s.gsub(%r[(\s|^)#{word}(\s|$)],%Q[\1#{id}\2]) > gets: bar foo bar foo > because the space after the first foo (bar) is ignored when looking for > the first space of the next word. does not work for me: irb(main):032:0> ": dbl dup + ;".gsub(%r[(\s|^)\+(\s|$)], %Q[\1:plus:\2]) => ": dbl dup\001:plus:\002;" something is wrong with \1 and \2 $ ruby --version ruby 1.7.3 (2002-12-17) [i586-linux] -- Radek Hnilica ======================================= No matter how far down the wrong road you've gone, turn back. Turkish proverb