Python sqlite and regex.

Dan Sommers me at
Fri May 19 15:08:17 CEST 2006

On Fri, 19 May 2006 14:47:10 +0200,
Julien ARNOUX <julien.arnoux at> wrote:

> cur.execute("select foo from test where foo regex 'aa.[0-9])")

> and the error is:

> cur.execute('select foo from test where foo regex tata')
> apsw.SQLError: SQLError: near "regex": syntax error

I think you're missing a closing quote on that regex; or perhaps that's
an extra closing parenthesis at the end.

Also, it's probably best to let the database module do any escaping you
may need.  For example:

    fooregex = r'aa.[0-9]'
    sql = 'select foo from test where foo regex %s'
    cur.execute( sql, tuple( fooregex ) )

See the DP API spec for more information.


Dan Sommers
"I wish people would die in alphabetical order." -- My wife, the genealogist

More information about the Python-list mailing list