Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex: How to ignore pairs of quotes? (beginner level question)

Reply
Thread Tools

Regex: How to ignore pairs of quotes? (beginner level question)

 
 
Tobias Weihmann
Guest
Posts: n/a
 
      04-23-2004
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?

Cheers!
Toby
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      04-23-2004
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
 
Reply With Quote
 
 
 
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      04-23-2004
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?

Someone else posted something like the following to a similar problem.

my example is tested, but just for the one example


# $s contains the VB string you wish to parse.

$s=q{print "This is a test ""Test"" yeah" + Str$(4)+ "good"};

# extract the quoted portions
@s= $s=~ m/"((?:[^"]|"")*)"/g;

# examine what we extracted
print map {"=>$_<=\n" } @s;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
c is a low-level language or neither low level nor high level language pabbu C Programming 8 11-07-2005 03:05 PM
Accessing higher security level from higher security level nderose@gmail.com Cisco 0 07-11-2005 10:20 PM
Ignore + TEST + Ignore SpooderStank Computer Support 2 04-08-2004 11:26 AM
Searching for Exact Phrase - should I ignore the ignore words? Rob Meade ASP General 6 03-01-2004 11:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57