Expressions library

This module contains AST nodes which already handle the most common tasks.

Example

That’s how to use the library

from nsre import *
from nsre.lib import email

re = RegExp.from_ast(email)
assert re.match('user@domain.com')

List

Here are all the available nodes

Python string tests

There is a series of nodes available which correspond to Python’s builtin string tests.

By example, ascii_alpha matches characters that Python would categorize as s.isascii() and s.isalpha(). Also, the plural version indicates a repetition of “one or more” of those characters. Literally,

ascii_alnum = Final(Test(lambda t: t.isalnum() and t.isascii()))
ascii_alnums = ascii_alnum * slice(1, None)

You have here the full list of those constants:

  • alnum

  • alnums

  • alpha

  • alphas

  • ascii_alnum

  • ascii_alnums

  • ascii_alpha

  • ascii_alphas

  • ascii_decimal

  • ascii_decimals

  • ascii_digit

  • ascii_digits

  • ascii_lower_alnum

  • ascii_lower_alnums

  • ascii_lower_alpha

  • ascii_lower_alphas

  • ascii_numeric

  • ascii_numerics

  • ascii_printable

  • ascii_printables

  • ascii_space

  • ascii_spaces

  • ascii_upper_alnum

  • ascii_upper_alnums

  • ascii_upper_alpha

  • ascii_upper_alphas

  • decimal

  • decimals

  • digit

  • digits

  • lower_alnum

  • lower_alnums

  • lower_alpha

  • lower_alphas

  • numeric

  • numerics

  • printable

  • printables

  • space

  • spaces

  • spaces_maybe

  • upper_alnum

  • upper_alnums

  • upper_alpha

  • upper_alphas

  • hex_digit

  • hex_digits

Common patterns

Other patterns are available:

  • domain_name: A domain name

  • email: An email address

  • url: An URL (HTTP or HTTPS)

  • html_tag: A HTML opening or self-closing tag