in reply to Re: matching quotes
in thread matching quotes

I was thinking if there is a single regex solution?

Replies are listed 'Best First'.
RE: RE: Re: matching quotes
by takshaka (Friar) on May 24, 2000 at 00:41 UTC
    #!/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.

RE: RE: Re: matching quotes
by perlmonkey (Hermit) on May 24, 2000 at 00:26 UTC
    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!)