[Mono-list] Regex question

Jaroslaw Kowalski jaak@zd.com.pl
Wed, 18 Feb 2004 13:58:50 +0100


I've tweaked it a bit, and it works. Don't ask me why ;-)

        string regex =
@"(('[^']*?\@[^']*')*[^'@]*?)*(?<param>@\w+)([^'@]*?('[^']*?\@[^']*'))*";

Basically I repeat first and second part with (*) and append the same thing
in reverse at the very end.

For:

        string textToMatch = "select * from test where int_field =
@int_field and char_field = 'carlosga@telefonica.net' and zzz=@aaa and
'a@b.com' = @zzz";

it prints:

3
match 0 is @int_field
match 1 is @aaa
match 2 is @zzz

Jarek

----- Original Message ----- 
From: "Carlos Guzmán Álvarez" <carlosga@telefonica.net>
To: "Jaroslaw Kowalski" <jaak@zd.com.pl>
Cc: "Chris Turchin" <chris@turchin.net>; "mono-list"
<mono-list@lists.ximian.com>
Sent: Wednesday, February 18, 2004 1:48 PM
Subject: Re: [Mono-list] Regex question


> Hello:
>
> > I think that Carlos wants to ignore the @ inside quotes. Here's the
proposed
> > solution:
>
> Correct, until now i was using:
>
> (@\w+)
>
> but it's not always valid and if i can i want to fix it :)
>
> > The regex consists of 3 parts:
> >
> > first part (optional) matches a quote followed by a sequence of
characters
> > including @ and terminated by a quote. This is used to kill quoted @.
> > the second part matches any sequence of characters other than a quote or
> > "at" sign the third part matches @ followed by a word.
>
> Thanks !! Seems to be valid, but not always, seems that it's going to be
> a little difficult to do this using regex :P
>
> For example in this case fails:
>
> select * from test where int_field = @int_field and char_field =
> 'carlosga@telefonica.net'
>
> It prints:
>
> 2
> match 0 is @int_field
> match 1 is @telefonica
>
>
>
>
> --
> Best regards
>
> Carlos Guzmán Álvarez
> Vigo-Spain
>