Skip to main content

Build complex one-line regex strings.

Project description

regex-build

Build complex one-line regex strings.

The preferred way of building is using a one line chain of calls on the RegexBuild instance. For anything more complex, using it as a context manager will allow for multiple calls to be made on the same instance.

Instances of RegexBuild may be used interchangeably with strings, allowing for multiple nested instances to be used.

>>> original_regex = r'.*\\Roaming\\(Microsoft|NVIDIA|Adobe\\.*(Asset|Native)Cache)\\'

# Complex example
>>> with RegexBuild(r'.*\\Roaming\\') as build_regex:
...     build_regex(
...         'Microsoft', 'NVIDIA', RegexBuild(r'Adobe\\.*')('Asset', 'Native')('Cache'),
...     )(r'\\')

>>> original_regex == str(build_regex)
True

# Different ways to build the same regex
>>> with RegexBuild('(?i)', exit='$') as case_insensitive:
...     # As one line
...     case_insensitive('prefix1_')('word1', 'word2')('_suffix1')
...
...     # As context managers
...     with case_insensitive('prefix2_') as prefix:
...         with prefix('word2', 'word3') as words:
...             words('_suffix2')
...
...     # As context manager using the "end" parameter
...     with case_insensitive('prefix3_', end='_suffix3') as prefix:
...         prefix('word4')
...         prefix('word5')
...

>>> case_insensitive
'(?i)(prefix1_(word1|word2)_suffix1|prefix2_(word3|word4)_suffix2|prefix3_(word5|word6)_suffix3)$'

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

regex-build-1.0.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file regex-build-1.0.1.tar.gz.

File metadata

  • Download URL: regex-build-1.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9

File hashes

Hashes for regex-build-1.0.1.tar.gz
Algorithm Hash digest
SHA256 70205b380f1ea46e96aab748e7c741c401e6845a81d4cdc9e4e7a51c35508d0b
MD5 ed1c947fc8c50d2daafa341466c1a481
BLAKE2b-256 fac2f3c3a4a56978a9aaa9c3a261c7ff37237d48fb40de515dccb5a377351a5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page