Python sqlite and regex.

Julien ARNOUX julien.arnoux at ext.cri74.org
Fri May 19 08:47:10 EDT 2006


Hi,
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()
#exampl
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

Thanks






More information about the Python-list mailing list