From: Simon Strandgaard Date: 2004-05-14T06:13:16+09:00 Subject: Re: nasty regexp problem David Alan Black wrote: > Simon Strandgaard writes: > > > Francis Hwang wrote: > > > I discovered a strange bug in Lafcadio which I'm trying to work out, > > > but the regexp is getting really nasty. Basically, to commit text > > > values to the database I need to double any apostrophe, except those > > > that are preceded by a backslash. This has to account for apostrophes > > > at the beginning of the string, and multiline strings where the > > > apostrophe is at the start of a new line. Examples would be: > > > > > > irb(main):001:0> "''\\\\'z\\'\\z''".gsub(/ ( (?: [^\\] | \\ . )*? ) ' /x, '\1\'\'') > > => "''''\\\\''z\\'\\z''''" > > The ' before the first z isn't supposed to get doubled though, is it? > The behavier is correct.. because its an escaped slash right before it. yes it can easily be confused with an ordinary slash. -- Simon Strandgaard