XP is just a number | |
PerlMonks |
Simple way to parse whitespace separated, optionally quoted words out of a stringby Aristotle (Chancellor) |
on Nov 16, 2002 at 02:09 UTC ( [id://213340]=CUFP: print w/replies, xml ) | Need Help?? |
I recently needed to parse words separated by whitespace out of a string, where a doublequoted word may contain spaces itself but no escaped doublequotes. The following regex will do, is quite tidy and also hardly backtracks (occasionally by a few characters, not more).
my @words = /"?((?<!")\S+(?!"\s)|[^"]+)"?\s*/g;
Back to
Cool Uses for Perl
|
|