GithubHelp home page GithubHelp logo

millarm / django-regex-field Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ambitioninc/django-regex-field

0.0 1.0 0.0 60 KB

Store regexs in a Django model

License: MIT License

Python 100.00%

django-regex-field's Introduction

Build Status

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.