From: "David A. Black" Date: 2009-10-21T00:37:15+09:00 Subject: Re: Complex GSUB query Hi -- On Wed, 21 Oct 2009, Ne Scripter wrote: > Hello all, > > I am struggling with something and I have yet been able to find anything > that may help me. > > I have a string like follows: > > string = "\"bloggs, Joe (JBloggs, INFO)\" joebloggs, \"bloggs, Bill > (BBloggs, INFO)\" billbloggs" > > I want to break this string up into two entries using a _ seperator, one > for Joe and the other for Bill. I could do this with a simple > > string.gsub(",", "_") > > However the problem with doing this is that there are commas elsewhere > in the string. So what I need to say is, if the comma is outside of "" > (quotes) replace it with the _ > > Could anyone possibly help me with this? It looks like the pattern /, "/ occurs at the end of one record into the beginning of the next one, and nowhere else. Assuming that's correct, it suggests something like: string.gsub(/,(?=\s+")/, '_') i.e., for any comma which is followed by some whitespace and a double quote character, replace the comma with an underscore. David -- The Ruby training with D. Black, G. Brown, J.McAnally Compleat Jan 22-23, 2010, Tampa, FL Rubyist http://www.thecompleatrubyist.com David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)