Skip to content

urigoren/nre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nice Regular Expressions

A simple wrapper around the re module that supports multiple patterns, and reuse of patterns.

Installation

pip install nre

Usage

import nre
patterns = nre.from_string(r'''
number=\d+
decimal={{number}}\.{{number}}
lowercase=[a-z]+
''')
print(patterns.decimal.findall("123.22")) # returns ['123.22']
print(patterns.number.findall("123.22")) # returns ['123', '22']
print(patterns.decimal.findall("abc"))  # returns []
print(patterns.lowercase.findall("abc"))  # returns ['abc']

We recommend using external pattern files

 import nre
 patterns = nre.from_file("patterns.nre")

If you use external files, you can import them within other files

# contents of users.nre
valid_username=[a-zA-z_]+

# contents of emails.nre
import users
valid_email={{valid_username}}@gmail.com

About

Nice Regular Expressions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages