- if settings.DATABASE_ENGINE in ('mysql', 'postgresql_psycopg2', 'postgresql'):
- prefix = _no_diacritics_regexp(re.escape(prefix))
- # we could use a [[:<:]] (word start),
- # but we want both `xy` and `(xy` to catch `(xyz)`
- kwargs['%s__iregex' % name] = u"(^|[^[:alpha:]])%s" % prefix
- else:
- # don't know how to do a generic regex
- # checking for simple icontain instead
- kwargs['%s__icontains' % name] = prefix
+
+ prefix = _no_diacritics_regexp(unicode_re_escape(prefix))
+ # can't use [[:<:]] (word start),
+ # but we want both `xy` and `(xy` to catch `(xyz)`
+ kwargs['%s__iregex' % name] = u"(^|[^[:alnum:]_])%s" % prefix
+