#!/usr/bin/perl -wl
use strict;
my $string = 'foo "A small \"dog\" eats pie." bar "foobar"';
print $1 while $string =~ /(?<!\\)"(.*?)(?<!\\)"/gs;
Addendum: Hmm. It didn't take me fifteen
minutes to write this post.
perlmonkey must be typing at relativistic speeds.
btw--double quotes are not special in a regex; you don't
need to backslash them. | [reply] [d/l] |
Here is a single regex inside the while loop, but it is slower: while ( $file =~ /((?<!\\)\".*?(?<!\\)\")/sg) {
print $1;
}
Update: takshaka is correct of course. I flaked out and
did not need to backslach the ", fortunatley it works
just fine either way, just more clutter.
I dont know about my relativistic typing. I guess
I am just that good :) Acutally I once took
a typing test and got around a -400 wpm (note the negative!) ...
apparently I got docked for extensively using the backspace key. (Either that
or I typed so damn fast that I overflowed the signed int ... yah, thats it, I really
typed 65136 wpm, man I'm good!)
| [reply] [d/l] |