Question about regular expressions involving quoted strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about regular expressions involving quoted strings

Andrew Smellie

Hi

 

I am trying to write a regular expression that will parse a quoted string

 

This is what I have so far:     QUOTEDSTRING = <<"([^"]|"")*+">>

 

How can I modify this to allow double quotes inside the quoted string, perhaps denoted by an escape character? An example of such a string might be:

 

"\"a quoted string\"" would be parsed to read "a quoted string"

 

As an aside, I cast around for different parser generators and have found grammatica the easiest to use!

 

Thanks

 

Andrew

 


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Question about regular expressions involving quoted strings

Per Cederberg
Try experimenting on http://regexpal.com/

Here is one that I got to work:

<<"([^"\\]|""|\\.)*">>

Cheers,

/Per

On Tue, May 19, 2009 at 19:17, Andrew Smellie <[hidden email]> wrote:

> Hi
>
>
>
> I am trying to write a regular expression that will parse a quoted string
>
>
>
> This is what I have so far:     QUOTEDSTRING = <<"([^"]|"")*+">>
>
>
>
> How can I modify this to allow double quotes inside the quoted string,
> perhaps denoted by an escape character? An example of such a string might
> be:
>
>
>
> "\"a quoted string\"" would be parsed to read "a quoted string"
>
>
>
> As an aside, I cast around for different parser generators and have found
> grammatica the easiest to use!
>
>
>
> Thanks
>
>
>
> Andrew
>
>
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>
>


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Question about regular expressions involving quoted strings

William Lahti
On Thu, May 21, 2009 at 4:55 AM, Per Cederberg <[hidden email]> wrote:
Here is one that I got to work:

<<"([^"\\]|""|\\.)*">>

Wouldn't that match """" as a single string? Here's what I've been using (I think it came from a Grammatica example somewhere):

<<[\"]([^"\\]|\\.)*[\"]>>

--
rezonant

long name: William Lahti
handle :: rezonant
freenode :: xfury
blog :: http://xfurious.blogspot.com/
site :: http://komodocorp.com/~wilahti

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Question about regular expressions involving quoted strings

Per Cederberg
Yes, it would. But I think that was part of the point with it.

/Per

On Thu, May 21, 2009 at 15:49, William Lahti <[hidden email]> wrote:

> On Thu, May 21, 2009 at 4:55 AM, Per Cederberg <[hidden email]> wrote:
>>
>> Here is one that I got to work:
>>
>> <<"([^"\\]|""|\\.)*">>
>
> Wouldn't that match """" as a single string? Here's what I've been using (I
> think it came from a Grammatica example somewhere):
>
> <<[\"]([^"\\]|\\.)*[\"]>>
>
> --
> rezonant
>
> long name: William Lahti
> handle :: rezonant
> freenode :: xfury
> blog :: http://xfurious.blogspot.com/
> site :: http://komodocorp.com/~wilahti
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>
>


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users