Readable regular expressions for Python 3.6 and up.
Project description
cursive_re
Readable regular expressions for Python 3.6 and up.
Installation
pip install cursive_re
Examples
>>> from cursive_re import *
>>> hash = text("#")
>>> hexdigit = any_of(in_range("0", "9") + in_range("a-f") + in_range("A-F"))
>>> hexcolor = (
... beginning_of_line() + hash +
... group(repeated(hexdigit, exactly=6) | repeated(hexdigit, exactly=3)) +
... end_of_line()
... )
>>> str(hexcolor)
'^\\#([a-f0-9]{6}|[a-f0-9]{3})$'
>>> hexcolor_re = compile(hexcolor)
re.compile('^\\#([a-f0-9]{6}|[a-f0-9]{3})$')
>>> hexcolor_re.match("#fff")
<re.Match object; span=(0, 4), match='#fff'>
>>> hexcolor_re.match("#ffff") is None
True
>>> hexcolor_re.match("#ffffff")
<re.Match object; span=(0, 7), match='#ffffff'>
>>> domain_name = one_or_more(any_of(in_range("a", "z") + in_range("0", "9") + text("-")))
>>> domain = domain_name + zero_or_more(text(".") + domain_name)
>>> path_segment = zero_or_more(none_of("/"))
>>> path = zero_or_more(text("/") + path_segment)
>>> url = (
... group(one_or_more(any_of(in_range("a", "z"))), name="scheme") + text("://") +
... group(domain, name="domain") +
... group(path, name="path")
... )
>>> str(url)
"(?P<scheme>[a-z]+)://(?P<domain>[a-z0-9\-]+(?:\.[a-z0-9\-]+)*)(?P<path>(?:/[^/]*)*)"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cursive_re-0.0.1.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cursive_re-0.0.1.tar.gz.
File metadata
- Download URL: cursive_re-0.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3433e9413b74bacbc2ed8c30dde321a5aab581b197a535d0659625adb5b7d7a
|
|
| MD5 |
8eb9e12d85c7ca84b36e0d670c20a5cd
|
|
| BLAKE2b-256 |
1c8d94df0eb6eae17e61e8b23809241050084e0263ab164449ae0a0cfd1ddea6
|
File details
Details for the file cursive_re-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cursive_re-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e74552f5857e5bb7c7cbf34cc9acd3d6a0ece4ed4a062a84f8e6dc9c0bbaee0
|
|
| MD5 |
7961d51f719e010e00f3b1acb06624b5
|
|
| BLAKE2b-256 |
b57a1bc8bcc2e11ed892834aa403a012b4c49ef8a2fe098ee399725d4ad2fa31
|