Skip to main content

Build and explain Python Regex patterns in a human-friendly way

Project description

PyPI Version PyPI Downloads

Description

regexplainer consists of two main components:
  • Explainer (technically RegexTokenizer): It tokenizes a given input regex string pattern, and its explain() method then explains in simpler English what is going on. The output is customizable, i.e. whether you want to see the flags, where a particular token starts and its length, to see the full textual sub-token along with its break-down, etc. In your IDE, check the init parameters to the class. This is working pretty well and you can use it without many issues.

  • Builder (technically RegexBuilder): This is a class that you can instantiate, and start using its properties and methods to build a regex without having to remember the actual Regex syntax. Your Python IDE will prompt you once you type in a letter that is close to what you want to do. Unfortunately, this is very rough around the edges and needs quite a bit of work. Am working on it.

Note: This is an alpha version, and things may change quite a bit.

from regexplain import RegexTokenizer


regtokens = RegexTokenizer(r"[^\w\s-]")
regtokens.explain()

"""
Explaining Full Pattern: [^\w\s-]
┌──
│   [Span, Length] (0, 8), 8
│   [Flags] re.NOFLAG
│  ┌──
│──│ [^
│  │   [@0:Character Set] Matches any character not in the set
│  │   [Span, Length] (0, 8), 8
│  │   [Flags] re.NOFLAG
│  │  ┌──
│  │──│ \w
│  │  │   [@1:Character Class:Word] Matches any word character (alphanumeric and underscore)
│  │  │   [Span, Length] (2, 4), 2
│  │  │   [Flags] re.NOFLAG
│  │  └──
│  │  ┌──
│  │──│ \s
│  │  │   [@2:Character Class:Whitespace] Matches any whitespace character (space, tab, line-break)
│  │  │   [Span, Length] (4, 6), 2
│  │  │   [Flags] re.NOFLAG
│  │  └──
│  │  ┌──
│  │──│ -
│  │  │   [@3:Literal] Matches a single character from the list '-' (case-sensitive)
│  │  │   [Span, Length] (6, 7), 1
│  │  │   [Flags] re.NOFLAG
│  │  └──
│  │ ]
│  │   [@0:End] Token closed
│  └──
└──
"""

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

regexplain-0.1.0a16.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

regexplain-0.1.0a16-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file regexplain-0.1.0a16.tar.gz.

File metadata

  • Download URL: regexplain-0.1.0a16.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.13.2 Windows/11

File hashes

Hashes for regexplain-0.1.0a16.tar.gz
Algorithm Hash digest
SHA256 b8f1cd61a554faa1aab54fbecfcabc2b81aa18a2effe45117179f0e7fd1be8f3
MD5 af48742194cebc21ad6d7aa8cb50b138
BLAKE2b-256 f8bf02daf0d53d0df88d401b4c61ff4a01f4e8da48a8d9b297e0dfec9b79fd59

See more details on using hashes here.

File details

Details for the file regexplain-0.1.0a16-py3-none-any.whl.

File metadata

  • Download URL: regexplain-0.1.0a16-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.13.2 Windows/11

File hashes

Hashes for regexplain-0.1.0a16-py3-none-any.whl
Algorithm Hash digest
SHA256 f9b6326b1f6215ad13ceec80b122574941f7a2cc8972eaa87e5914ba66d01647
MD5 d875825d96899cc0d50441da542da196
BLAKE2b-256 812ef34a56e8248ca3b451cd8d36bc12c956cb3e14db65de5be149404712ed10

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