#!/usr/bin/perl -w use strict; while (<DATA>) { print "input: $_"; my @tokens = grep{defined($_)}m/"(.*?)"|(\S+)/g; foreach my $tok (@tokens) { print " $tok\n"; } } #or while (<DATA>) { print "input: $_"; my @tokens = m/"(.*?)"|(\S+)/g; foreach my $tok (@tokens) { next unless defined($tok); print " $tok\n"; } } =prints input: - "adf adf" - "something else" - adf adf - something else input: "another line" - - "adf" another line - - adf input: abc = 24 "adf adf" abc = 24 adf adf input: -56 ouy "97 lkh wer" - 87 -98 -56 ouy 97 lkh wer - 87 -98 =cut __DATA__ - "adf adf" - "something else" "another line" - - "adf" abc = 24 "adf adf" -56 ouy "97 lkh wer" - 87 -98
In reply to Re: Regex: Matching quoted text
by Marshall
in thread Regex: Matching quoted text
by cmm7825
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |