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.
Use Text::ParseWords:
Output:
C:\Temp> ff $VAR1 = [ 'abcd', 'efgh', 'ijklm no pqrs', 'tuv' ];You can look at the source code for
Text::ParseWords::parse_lineto see the pattern used.