跳转到主要内容

用于在Django中处理正则表达式的字段和实用工具

项目描述

https://badge.fury.io/py/django-regex.png https://travis-ci.org/saxix/django-regex.png?branch=master https://pypip.in/d/django-regex/badge.png

用于在Django中处理正则表达式的字段和实用工具

Django regex字段为存储正则表达式的Django模型提供自定义字段和实用工具。这允许您轻松存储正则表达式模式,并在模型中将它们作为编译后的正则表达式访问。

可以使用perl语法来设置正则表达式标志。

组件

RegexField

用于存储正则表达式的Django字段

class DemoModel(models.Model):
    regex = RegexField(flags=re.I)


o = DemoModel.objects.create(regex='^1$')
o.regex.match('1')

RegexFlagsField

类似于RegexField,但允许设置编译标志(见:https://docs.pythonlang.cn/2/howto/regex.html#compilation-flags)。它使用适当的小部件进行渲染

from django_regex.validators import compress
import re

class DemoModel(models.Model):
    regex = RegexFlagsField()

o = DemoModel.objects.create(regex=compress(['aa', re.I]))
o.regex.match('AA')

o = DemoModel.objects.create(regex=compress(['aa', 'i'])) # use human shortcuts
o.regex.match('AA')

RegexFlagsField将模式和标志存储在数据库列中,列格式为<regex.pattern><separator><regex.flags>

分隔符为chr(0),可以使用设置DJANGO_REGEX_SEPARATOR或使用flags_separator参数在每个字段中进行自定义。

from django_regex.validators import compress
import re

class DemoModel(models.Model):
    regex = RegexFlagsField(flags_separator='/')

o = DemoModel.objects.create(regex='aa/i')
o.regex.match('AA')

RegexList

匹配有效正则表达式的列表

rules = RegexList(['\d*'])
1 in rules  # True
'1' in rules  # True
'a' in rules  # False

项目详情


下载文件

为您的平台下载文件。如果您不确定要选择哪个,请了解更多关于安装软件包的信息。

源分布

django-regex-0.5.0.tar.gz (26.2 kB 查看哈希值)

上传时间

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面