corelibs-regex-checks (1.0.0)
Installation
pip install --index-url --extra-index-url https://pypi.org/simple corelibs-regex-checksAbout this package
CoreLibs Regex Checks
CoreLibs Python Regex Checks
This is part of the Python CoreLibs
Overview
Regex Check constants
Install
uv add --index opj-pypi=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ corelibs-regex-check
Usage
This module contains
- corelibs_regex_check.regex_constants_compiled
- corelibs_regex_check.regex_constants
Regex Check usage
from corelibs_regex_check.regex_constants_compiled import (
COMPILED_EMAIL_BASIC_REGEX,
COMPILED_NAME_EMAIL_SIMPLE_REGEX,
COMPILED_NAME_EMAIL_BASIC_REGEX,
COMPILED_DOMAIN_WITH_LOCALHOST_REGEX,
COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX,
COMPILED_DOMAIN_REGEX
)
from corelibs_regex_check.regex_constants import (
SUB_EMAIL_BASIC_REGEX,
EMAIL_BASIC_REGEX,
NAME_EMAIL_SIMPLE_REGEX,
NAME_EMAIL_BASIC_REGEX,
DOMAIN_WITH_LOCALHOST_REGEX,
DOMAIN_WITH_LOCALHOST_PORT_REGEX,
DOMAIN_REGEX
)
<code>
If no further sub use of the regex is is needed, for example in another regex, it is recommended to use the compiled version.
regex_constants.compile_re
Compiles a regex and returnes the compiled string. Will throw ValueError if the regex cannot be compiled
from corelibs_regex_check.regex_constants import {
compile_re, EMAIL_BASIC_REGEX
}
email_basix_regex_compiled = None
try:
email_basix_regex_compiled = compile_re(EMAIL_BASIC_REGEX)
except ValueError as e:
print(f"Cannot compile regex: {e}")
SUB_EMAIL_BASIC_REGEX
Sub part for all the email regex, normally not needed, used *EMAIL_BASIC_REGEX
COMPILED_EMAIL_BASIC_REGEX, EMAIL_BASIC_REGEX
The basic email regex, no matching parts returned
COMPILED_NAME_EMAIL_SIMPLE_REGEX, NAME_EMAIL_SIMPLE_REGEX
Uses a very somple check flow, does not check for a valid email itself, but for string patterns.
Matches any valid email format for mail sending in the type of with the following parts returned
"Some name" <user@email.com>- name1:
Some name - email1:
user@email.com
- name1:
Some name <user@email.com>- name2:
Some name - email2:
user@email.com
- name2:
<user@email.com>- email3:
user@email.com
- email3:
user@email.com- email4:
user@email.com
- email4:
COMPILED_NAME_EMAIL_BASIC_REGEX, NAME_EMAIL_BASIC_REGEX
Exactle the same as above, but uses the "SUB_EMAIL_BASIC_REGEX" regex instead of very simple checks.
COMPILED_DOMAIN_WITH_LOCALHOST_REGEX, DOMAIN_WITH_LOCALHOST_REGEX
Checks for a domain name, and allows "localhost" to be valid.
COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX, DOMAIN_WITH_LOCALHOST_REGEX
Same as above, but also allowes an optional port number at the end. Note the Port number is not checked for a valid port number itself, this has to be done in a seprate check.
COMPILED_DOMAIN_REGEX, DOMAIN_REGEX
Normal domain check, but do not allow "localhost" to be valid
Development
UV setup
uv must be installed
Python venv setup
After clone, run the command below to install all dependenciss
uv sync
Build and Publish
uv build
uv publish --index opj-pypi --token <gitea token>
Python tests
All python tests are the tests/ folder. They are structured by the source folder layout
run them with
uv run pytest
Get a coverate report
uv run pytest --cov=<project>
uv run pytest --cov=<project> --cov-report=term-missing
Other tests
In the test-run folder usage and run tests are located, runt them below
uv run test-run/<script>