how do i capture all quoted strings?
this gives an error:
print "$str1\n";
($one, $two) = $str1 =~/"([^(?:[^"]")]*)" (\d+)/;
print "$one $two\n";
what i want is:
$str1 = "\"something\" 444";
$str1 = "\"\\\"escaped quote\\\" 321";
$str1 = "\"\\\"esc quote\\\" other stuff\" 567";
to match - and sometimes there are spaces before the match, a '\' with
no '"', etc. i'm trying to match a useragent in an apache log file.
i've gone through the source of a few modules that claim to do this
and i can't figure out how they're doing it.
here's a test (the later case is what's really got me btw):
#!/usr/bin/perl
use strict;
use warnings;
my $str0 = "thing other";
print "$str0\n";
my ($sane) = $str0 =~ /(\S+)(?: other)/;
print "$sane \n";
foreach my $str(("\"something\" 444",
"\"\\\"escaped quote\\\" 321", "\"\\\"esc
quote\\\" other stuff\" 567",
"\"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .
NET CLR 1.1.4322; msn OptimizedIE8;ESMX)\" 556",
"\"\\\"Mozilla\\\"\" 555"
)) {
print "$str\n";
my ($one, $two) = $str =~/"([^"]*)" (\d+)/;
print "[$one] [$two]\n";
}
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/