| | 1176 | regex |
|---|
| | 1177 | ~~~~~ |
|---|
| | 1178 | |
|---|
| | 1179 | **New in Django development version** |
|---|
| | 1180 | |
|---|
| | 1181 | Case-sensitive regular expression match. |
|---|
| | 1182 | |
|---|
| | 1183 | The regular expression syntax is that of the database backend in use. In the |
|---|
| | 1184 | case of SQLite, which doesn't natively support regular-expression lookups, the |
|---|
| | 1185 | syntax is that of Python's ``re`` module. |
|---|
| | 1186 | |
|---|
| | 1187 | Example:: |
|---|
| | 1188 | |
|---|
| | 1189 | Entry.objects.get(title__regex=r'^(An?|The) +') |
|---|
| | 1190 | |
|---|
| | 1191 | SQL equivalents:: |
|---|
| | 1192 | |
|---|
| | 1193 | SELECT ... WHERE title REGEXP BINARY '^(An?|The) +'; -- MySQL |
|---|
| | 1194 | |
|---|
| | 1195 | SELECT ... WHERE REGEXP_LIKE(title, '^(an?|the) +', 'c'); -- Oracle |
|---|
| | 1196 | |
|---|
| | 1197 | SELECT ... WHERE title ~ '^(An?|The) +'; -- PostgreSQL |
|---|
| | 1198 | |
|---|
| | 1199 | SELECT ... WHERE title REGEXP '^(An?|The) +'; -- SQLite |
|---|
| | 1200 | |
|---|
| | 1201 | Using raw strings (e.g., ``r'foo'`` instead of ``'foo'``) for passing in the |
|---|
| | 1202 | regular expression syntax is recommended. |
|---|
| | 1203 | |
|---|
| | 1204 | Regular expression matching is not supported on the ``ado_mssql`` backend. |
|---|
| | 1205 | It will raise a ``NotImplementedError`` at runtime. |
|---|
| | 1206 | |
|---|
| | 1207 | iregex |
|---|
| | 1208 | ~~~~~~ |
|---|
| | 1209 | |
|---|
| | 1210 | **New in Django development version** |
|---|
| | 1211 | |
|---|
| | 1212 | Case-insensitive regular expression match. |
|---|
| | 1213 | |
|---|
| | 1214 | Example:: |
|---|
| | 1215 | |
|---|
| | 1216 | Entry.objects.get(title__iregex=r'^(an?|the) +') |
|---|
| | 1217 | |
|---|
| | 1218 | SQL equivalents:: |
|---|
| | 1219 | |
|---|
| | 1220 | SELECT ... WHERE title REGEXP '^(an?|the) +'; -- MySQL |
|---|
| | 1221 | |
|---|
| | 1222 | SELECT ... WHERE REGEXP_LIKE(title, '^(an?|the) +', 'i'); -- Oracle |
|---|
| | 1223 | |
|---|
| | 1224 | SELECT ... WHERE title ~* '^(an?|the) +'; -- PostgreSQL |
|---|
| | 1225 | |
|---|
| | 1226 | SELECT ... WHERE title REGEXP '(?i)^(an?|the) +'; -- SQLite |
|---|
| | 1227 | |
|---|