Python sqlite and regex.

Julien ARNOUX julien.arnoux at
Fri May 19 14:47:10 CEST 2006

I'd like to use regular expressions in sqlite query, I using apsw module
but it doesn't work...Can you help me ?
My script:

import apsw
import re

path = 'db/db.db3'

#regexp function (extract from python-list discusion)
def regexp(expr, item):
    reg = re.compile(expr)
    return reg.match(item) is not None

con = apsw.Connection(path)
#create function
con.createscalarfunction("REGEXP", regexp)
cur = con.cursor()
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


More information about the Python-list mailing list