in reply to split on spaces, except those within quotes?
I probably deserve hate mail for this one but...
#! perl -sw use strict; sub tokenize ($) { local $_ = shift; s/(('|").*?\2)/ ($£ = $1) =~ s!\s+!\cA!g; $£ /ge; #!" grep{s/\cA/ /g, $_}split/\s+/; } my @bits = tokenize q/a "b c d" e f 'g h' ijk "l m n " op 'q r s +t' u'v w'x yz/; local $,='|'; print @bits,$/; __END__ c:\test>212174 a|"b c d"|e|f|'g h'|ijk|"l m n "|op|'q r s t'|u'v w'x|yz|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: split on spaces, except those within quotes?
by diotalevi (Canon) on Nov 12, 2002 at 03:36 UTC | |
by jryan (Vicar) on Nov 12, 2002 at 04:40 UTC | |
by diotalevi (Canon) on Nov 12, 2002 at 04:49 UTC | |
|
Re^2: split on spaces, except those within quotes?
by SwaJime (Scribe) on Feb 04, 2021 at 13:26 UTC | |
by haukex (Archbishop) on Feb 04, 2021 at 13:42 UTC | |
|
Re: Re: split on spaces, except those within quotes?
by John M. Dlugosz (Monsignor) on Nov 12, 2002 at 17:09 UTC | |
by BrowserUk (Patriarch) on Nov 12, 2002 at 22:18 UTC |