From: email55555@... Date: 2005-10-04T23:56:49+09:00 Subject: Re: Splitting a string with escapable separator? Without 1.9 lookback, you could try: 'Hello\,World,Hi'.scan(/(?:\\,|[^,])+/).map {|e| e.tr('\\','')} => ["Hello,World", "Hi"] Michael Schuerig wrote: > I'm trying to come up with an *elegant* way to split a string into an > array at a separator with the additional feature that the separators > can be escaped. It should work like this > > "Hello\, World,Hi".split_escapable(',' '\') > # => ["Hello, World", "Hi"] > > Through a number of permutations with regexps, scan and the rest of the > family, I was unable to find a solution. I could parse the given string > myself, going though it character by character, but I'd prefer a less > pedestrian approach. > > Michael > > -- > Michael Schuerig All good people read good books > mailto:michael@schuerig.de Now your conscience is clear > http://www.schuerig.de/michael/ --Tanita Tikaram, Twist In My Sobriety