Tobias Weihmann <> wrote:
> Hi,
>
> I'm trying to parse VB strings here but I didn't succeed in getting
> the regex to ignore pairs of double quotes (which are the equivalent to
> \" in Perl)
>
> Example:
>
> print "This is a test ""Test"" yeah" + Str$(4)+ "good"
> --> This is a test ""Test"" yeah
> --> good
>
> print """We""are""testing"""+"What they can do" '
> --> ""We""are""testing""
> --> What they can do
>
> I finished off writing a FSM, but this is quite clumsy compared to a
> regex. The best thing I had was like /"(.*?)"[^"]/, but this would get me
> --> This is a test "
> for the first example... ( the "T satisfies the end condition, even though
> the two quotes should be ignored altogether)
>
> I also considered /"(.*?[^"])"[^"]/, but this will break in the second
> example - because it is's of course possible to have two quotes (to be
> ignored) right before a quote finishing of the string. I also experi-
> mented with non-moving sequences (?!"") but to no avail...
>
> How would you do it?
print "$1\n" while /"(([^"]|"")*)"/g;
or, if you want to be able to read what you've written:
print "$1\n" while /"(
( [^"] | "" )*
)"
/gx;
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas