How can I split a string by whitespace unless inside of a single quoted string?

Posted by Kivin on Stack Overflow See other posts from Stack Overflow or by Kivin
Published on 2010-03-17T03:27:01Z Indexed on 2010/03/17 3:41 UTC
Read the original article Hit count: 339

Filed under:
|
|

I'm seeking a solution to splitting a string which contains text in the following format:

"abcd efgh 'ijklm no pqrs' tuv"

which will produce the following results:

['abcd', 'efgh', 'ijklm no pqrs', 'tuv']

In other words, it splits by whitespace unless inside of a single quoted string. I think it could be done with .NET regexps using "Lookaround" operators, particularly balancing operators. I'm not so sure about Perl.

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex