Python sqlite and regex.

Paul McGuire ptmcg at austin.rr._bogus_.com
Fri May 19 14:52:38 EDT 2006


"Dan Sommers" <me at privacy.net> wrote in message
news:m2u07lq2s5.fsf at unique.fqdn...
> On Fri, 19 May 2006 17:44:45 GMT,
> "Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote:
>
> > "Gerhard Häring" <gh at ghaering.de> wrote in message
> > news:mailman.5966.1148057291.27775.python-list at python.org...
>
> >> """
> >> The REGEXP operator is a special syntax for the regexp() user
> >> function. No regexp() user function is defined by default and so use
> >> of the REGEXP operator will normally result in an error message. If a
> >> user-defined function named "regexp" is defined at run-time, that
> >> function will be called in order to implement the REGEXP operator.
> >> """
>
> > This is very interesting.  So I *could* define my own regexp function
> > that processes not regular expressions, but say, glob-like strings,
> > which are usually much easier for end users to work with (very basic
> > wild-carding where '*' matches one or more characters, and '?' matches
> > any single character - maybe add '#' to match any single digit and '@'
> > to match any single alpha character).
>
> Doesn't SQL already have lightweight wildcards?
>
>     SELECT somefield FROM sometable WHERE someotherfield LIKE '%foo%'
>

Yes it does - '%' is like '*', and '_' is like '?'.  But it is rare for
application users to be familiar with these.  In my experience, users are
more likely to have seen '*' and '?'.

The reason I keep citing end/application users, as opposed to developers, is
for the case where the user has filled in some kind of wildcard search
field, to be passed to SQL in a query.  Woe to the app designer who figures
that users want to enter a regular expression in such a field.  '%' and '_'
wildcards a little better, but frankly, I think '*' and '?' looks more like
a wildcards than '%' and '_'.

-- Paul





More information about the Python-list mailing list