Problem with regexp python and sqlite

前端 未结 3 1197
余生分开走
余生分开走 2020-12-05 08:48

I try to check a string with a pattern using a regex with python on a sqlite database. I have problem when I try de search string having \" with a patern using \" For exempl

3条回答
  •  不知归路
    2020-12-05 09:11

    You can use triple escapes, or a raw string.

    Your doing:

    >>> print("select subject from articles where  subject regexp '\"test\"' ")
    select subject from articles where  subject regexp '"test"'
    

    Use a raw string, which is a r'string with a r in front':

    >>> print(r"select subject from articles where  subject regexp '\"test\"' ")
    select subject from articles where  subject regexp '\"test\"' 
    

    Or triple escapes (\\\):

    >>> print("select subject from articles where  subject regexp '\\\"test\\\"' ")
    select subject from articles where  subject regexp '\"test\"'
    

提交回复
热议问题