Django Regex Field
Project description
django-regex-field
Stores regular expressions in Django models.
A Brief Overview
The Django regex field app provides a custom field for a Django model that stores a regex. This provides the ability to easily store regexs and access them as compiled regular expressions from your models.
Storing and Retrieving a Regex
A regular expression can be stored and retrieved in a Django model as follows:
from django.db import models
from regex_field.fields import RegexField
class RegexModel(models.Model):
regex = RegexField(max_length=128)
model_obj = RegexModel.objects.create(regex='a')
# Access the regex as a compiled regular expression
>>> print(model_obj.regex.match('b'))
None
Using regex flags
Flags can be provided in the field definition and will be applied when the regex is compiled. If you manually compile a regex object with other flags and set it on the model, those flags will not be preserved. Only the flags passed to the field's constructor are used.
import re
from django.db import models
from regex_field.fields import RegexField
class RegexModel(models.Model):
regex = RegexField(max_length=128, re_flags=re.IGNORECASE)
model_obj = RegexModel.objects.create(regex='A')
# Case insensitive matching
>>> print(model_obj.regex.match('a') is not None)
True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-regex-field-3.1.0.tar.gz
.
File metadata
- Download URL: django-regex-field-3.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e17e7296e8d8c6fb68f30342eb6c88ec0336d811a22f7f180717f71e6c1e3fd6 |
|
MD5 | e30a1d5799516603dec3ab5f42d34312 |
|
BLAKE2b-256 | ca902f794e40e5a512abfa227efb7edd8ea50d780848aba98a74fc4f46998078 |
File details
Details for the file django_regex_field-3.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_regex_field-3.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d4f5c8dd60f187cf45e11ea01011b86fc18bc15ff31de91a7fd438e2b1037a2 |
|
MD5 | 42b68f3939d1b46a3069f5c5cfb8d62d |
|
BLAKE2b-256 | d89999aaaf79948f032883f156dfe107a877c5a48467f2cf90aea32b7aebe55c |