in reply to Re: Re: In need of a stupid regex trick
in thread In need of a stupid regex trick
Slight tweaks to require space around "quoted string" (which you may or may not want) and remove undef entries. Update: and remove empty entries.
perl -wle'@list = grep defined && length, split /(?:(?<!\S)"([^"]*)"(? +!\S))|\s+/, shift;print for @list' 'one "two three" four "five"'
perl -wle'@list = grep defined, split /(?:(?<!\S)"([^"]*)"(?!\S))|\s+/ +, shift;print for @list' 'one "two three" four "five"'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: In need of a stupid regex trick
by Anonymous Monk on Jan 05, 2004 at 07:04 UTC | |
by ysth (Canon) on Jan 05, 2004 at 11:45 UTC |