From: Gavin Kistner Date: 2004-03-12T11:22:49+09:00 Subject: Re: Regular Expression for D(elimiter) Separated Values File On Mar 11, 2004, at 3:40 PM, Warren Brown wrote: > Now to your original intent, it sounds like what you want is to split > on any semicolon that is not preceded by a backslash. This is a > little more difficult, since there is no "look-behind" construct in > regular expressions. To be pedantic - not in /Ruby's current implementation of/ regular expressions. This should all change in 2.0 with Oniguruma, right? Anyhow, if the above is an accurate assessment of the needs, just for the fun you can do it another way than the (effective) solution already provided. str = "aaa;bbb;ccc\\;ccc;ddd\\\\;eee;fff\\\\\\;fff;ggg\\\\\\\\;hhh"; chunks = str.gsub(/([^\\])(\\\\)*;/,'\1\2�').split('�').inspect; The premise here is to replace the desire for a negative lookbehind with a consumed character, which is then stuck back into the string along with a new 'magic' character which is guaranteed not to be in the source string. This character is then used to split the output. The regular expression above says "find a character which isn't a backslash, followed be an even number of backslashes, followed by a semi-colon (which we now know must be a field delimiter, since it can't have been escaped)". Seems to work from the naive sample I posted above...but requires a magic character to be available. -- (-, /\ \/ / /\/