From: Johnny Morrice Date: 2011-05-27T02:43:15+09:00 Subject: Re: Need help bringing select array lines together > The code reads in each line of an array, looks for a closing/ending " > and puts multiple lines into one element of another array if they are > part of the same string. Do you need to handle nested strings? Here is a crude solution that doesn't. I tried it on 1.9.2 # The messy input mess = [ " \"Only one line.\"", " \"line 1 ", " line 2.\"" ] # A single string, from the mess concatenated single = mess.join "" # Find all matches of the regex matches = single.scan /("[^"]*")/ # Flatten those results, # to get lines lines = matches.flatten # Pretty print the lines p lines I don't think any regex, being a finite automaton, could handle nested strings properly. Have you considered writing a small lexer and parser? You may be better doing that, can handle weirder strings too. Cheers, Johnny