backslash escapes regex

19 views
Skip to first unread message

ncsaba

unread,
Jul 26, 2012, 10:33:53 AM7/26/12
to sqlp...@googlegroups.com
Hi all,

In the lexer.py file there's a TODO about backslash escapes - for me the following regex worked well:

(r"('([^\\]|\\.)*?')", tokens.String.Single),

The same for the double-quote strings (which BTW is used for alias quoting):

(r'("([^\\]|\\.)*?")', tokens.String.Single),

I haven't tested this very extensively, but it did work on a fairly complex postgres SQL (a 10K string) with aliases and backslash quoted characters in strings.

With the hope this is helpful, I personally don't have the time to follow it up...

Cheers,
Csaba.




Andi Albrecht

unread,
Jul 27, 2012, 1:44:35 AM7/27/12
to sqlp...@googlegroups.com
Hi Csaba,

On Thu, Jul 26, 2012 at 4:33 PM, ncsaba <ncs...@gmail.com> wrote:
> Hi all,
>
> In the lexer.py file there's a TODO about backslash escapes - for me the
> following regex worked well:
>
> (r"('([^\\]|\\.)*?')", tokens.String.Single),
>
> The same for the double-quote strings (which BTW is used for alias quoting):
>
> (r'("([^\\]|\\.)*?")', tokens.String.Single),
>
> I haven't tested this very extensively, but it did work on a fairly complex
> postgres SQL (a 10K string) with aliases and backslash quoted characters in
> strings.

The regex looks good! Would you mind to prepare a patch with some unit
tests? One or two simple and typical example statements to test the
regex would be great!

Best regards,

Andi

>
> With the hope this is helpful, I personally don't have the time to follow it
> up...
>
> Cheers,
> Csaba.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlparse" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sqlparse/-/mH--rMk8f3EJ.
> To post to this group, send email to sqlp...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlparse+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlparse?hl=en.
Reply all
Reply to author
Forward
0 new messages