https://github.com/tristanlatr/sre_parse36
Python 3.6 sre_parse module
https://github.com/tristanlatr/sre_parse36
Last synced: 3 months ago
JSON representation
Python 3.6 sre_parse module
- Host: GitHub
- URL: https://github.com/tristanlatr/sre_parse36
- Owner: tristanlatr
- License: gpl-3.0
- Created: 2021-10-29T17:30:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T17:18:58.000Z (over 3 years ago)
- Last Synced: 2025-01-12T18:27:12.738Z (4 months ago)
- Language: Python
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python 3.6 ``sre_parse`` module
### Why
The initial motivation to "create" ``sre_parse36`` is to provide a colorizer for regular expressions that produce the *same* expression as initially provided.
The handling of non-capturing groups changed from Python 3.7, we can't back reproduce the original regular expression from a ``SubPattern`` instance anymore. This regression is tracked at https://bugs.python.org/issue45674, hopefully it will be fixed in a future Python 3.9 bugfix release.
In Python 3.6:
```python
>>> import sre_parse
>>> sre_parse.parse("(?:foo (?:bar) | (?:baz))").dump()
SUBPATTERN None 0 0
BRANCH
LITERAL 102
LITERAL 111
LITERAL 111
LITERAL 32
SUBPATTERN None 0 0
LITERAL 98
LITERAL 97
LITERAL 114
LITERAL 32
OR
LITERAL 32
SUBPATTERN None 0 0
LITERAL 98
LITERAL 97
LITERAL 122
```In Python 3.7 and beyond:
```python
>>> import sre_parse
>>> sre_parse.parse("(?:foo (?:bar) | (?:baz))").dump()
BRANCH
LITERAL 102
LITERAL 111
LITERAL 111
LITERAL 32
LITERAL 98
LITERAL 97
LITERAL 114
LITERAL 32
OR
LITERAL 32
LITERAL 98
LITERAL 97
LITERAL 122
```### Install
```
pip install sre_parse36
```### Usage
Replace ``sre_parse`` by ``sre_parse36``.