regex-enumerator


Nameregex-enumerator JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/Buba98/regex_enumerator
SummaryEnumerate all strings that match a given regex
upload_time2025-01-04 00:56:19
maintainerNone
docs_urlNone
authorVincenzo Greco
requires_python>=3.10
licenseMIT
keywords regex regex enumerator regular expression enumerator string generation exhaustive matching exhaustive search regex testing regex tools string enumeration data generation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Regex enumerator

[![PyPI version](https://img.shields.io/pypi/v/regex-enumerator.svg)](https://pypi.org/project/regex-enumerator/)

This library is meant to generate all the strings that match a given regex pattern. It is written in python and uses no external libraries.

## Installation

```bash
pip install regex-enumerator
```

## Usage

Here's an example of how to use the library:

```python
from regex_enumerator import RegexEnumerator

# Create a RegexEnumerator
re = RegexEnumerator(r'a[0-9]b')

# Get the next string that matches the regex
print(re.next()) # a0b
print(re.next()) # a1b
print(re.next()) # a2b
```

## What is supported

- [x] Character classes
- [x] Quantifiers (greedy)
- [x] Groups (named and unnamed)
- [x] Alternation
- [x] Escaped characters
- [x] Backreferences (named and unnamed)
- [x] Non-capturing groups

## What I plan to support

I think those features would slow down the library too much and they are not widely used. If you have suggestions on how to implement them efficiently, please let me know.

- [ ] Lookahead
- [ ] Lookbehind

## What is not supported

- [ ] Unicode properties
- [ ] Word boundaries
- [ ] Anchors
- [ ] Non-greedy quantifiers

## Charset

The library supports ASCII characters by default. To handle Unicode characters, include them explicitly in your regex or define a custom character set.

```python
from regex_enumerator import RegexEnumerator

# Directly in regex
regex_enum = RegexEnumerator(r'£')
print(regex_enum.next())  # £

# Using additional_charset
unicode_charset = [chr(i) for i in range(ord('¡'), ord('£'))]
unicode_charset = ['¡', '¢', '£']
unicode_charset = '¡¢£'
unicode_charset = ['¡¢', '£']

regex_enum = RegexEnumerator(r'.', additional_charset=unicode_charset)

result = []
while (char := regex_enum.next()) is not None:
    result.append(char)

assert '¡' in result
assert '¢' in result
assert '£' in result
```

## How it works

This library works by parsing the regex pattern into a tree structure. Once parsed, it performs a breadth-first search (BFS) on the tree to generate all matching strings. This ensures it does not get stuck on unbounded quantifiers for character classes or groups.

## Tests

The library includes a comprehensive test suite. To run the tests, use the following command:

```bash
pytest
```

## License

I don't know what license to use, so I'm going to use the MIT license. If you have any suggestions, please let me know.

## Contributors

Feel free to contribute to this project. I'm open to suggestions and improvements.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Buba98/regex_enumerator",
    "name": "regex-enumerator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "regex, regex enumerator, regular expression, enumerator, string generation, exhaustive matching, exhaustive search, regex testing, regex tools, string enumeration, data generation",
    "author": "Vincenzo Greco",
    "author_email": "grecovincenzo98@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/26/98e996d2771fd78920a86f6fc8b0344d4a8ce16e5e53f8b9c8526316c573/regex_enumerator-1.0.0.tar.gz",
    "platform": null,
    "description": "# Regex enumerator\n\n[![PyPI version](https://img.shields.io/pypi/v/regex-enumerator.svg)](https://pypi.org/project/regex-enumerator/)\n\nThis library is meant to generate all the strings that match a given regex pattern. It is written in python and uses no external libraries.\n\n## Installation\n\n```bash\npip install regex-enumerator\n```\n\n## Usage\n\nHere's an example of how to use the library:\n\n```python\nfrom regex_enumerator import RegexEnumerator\n\n# Create a RegexEnumerator\nre = RegexEnumerator(r'a[0-9]b')\n\n# Get the next string that matches the regex\nprint(re.next()) # a0b\nprint(re.next()) # a1b\nprint(re.next()) # a2b\n```\n\n## What is supported\n\n- [x] Character classes\n- [x] Quantifiers (greedy)\n- [x] Groups (named and unnamed)\n- [x] Alternation\n- [x] Escaped characters\n- [x] Backreferences (named and unnamed)\n- [x] Non-capturing groups\n\n## What I plan to support\n\nI think those features would slow down the library too much and they are not widely used. If you have suggestions on how to implement them efficiently, please let me know.\n\n- [ ] Lookahead\n- [ ] Lookbehind\n\n## What is not supported\n\n- [ ] Unicode properties\n- [ ] Word boundaries\n- [ ] Anchors\n- [ ] Non-greedy quantifiers\n\n## Charset\n\nThe library supports ASCII characters by default. To handle Unicode characters, include them explicitly in your regex or define a custom character set.\n\n```python\nfrom regex_enumerator import RegexEnumerator\n\n# Directly in regex\nregex_enum = RegexEnumerator(r'\u00a3')\nprint(regex_enum.next())  # \u00a3\n\n# Using additional_charset\nunicode_charset = [chr(i) for i in range(ord('\u00a1'), ord('\u00a3'))]\nunicode_charset = ['\u00a1', '\u00a2', '\u00a3']\nunicode_charset = '\u00a1\u00a2\u00a3'\nunicode_charset = ['\u00a1\u00a2', '\u00a3']\n\nregex_enum = RegexEnumerator(r'.', additional_charset=unicode_charset)\n\nresult = []\nwhile (char := regex_enum.next()) is not None:\n    result.append(char)\n\nassert '\u00a1' in result\nassert '\u00a2' in result\nassert '\u00a3' in result\n```\n\n## How it works\n\nThis library works by parsing the regex pattern into a tree structure. Once parsed, it performs a breadth-first search (BFS) on the tree to generate all matching strings. This ensures it does not get stuck on unbounded quantifiers for character classes or groups.\n\n## Tests\n\nThe library includes a comprehensive test suite. To run the tests, use the following command:\n\n```bash\npytest\n```\n\n## License\n\nI don't know what license to use, so I'm going to use the MIT license. If you have any suggestions, please let me know.\n\n## Contributors\n\nFeel free to contribute to this project. I'm open to suggestions and improvements.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Enumerate all strings that match a given regex",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Buba98/regex_enumerator"
    },
    "split_keywords": [
        "regex",
        " regex enumerator",
        " regular expression",
        " enumerator",
        " string generation",
        " exhaustive matching",
        " exhaustive search",
        " regex testing",
        " regex tools",
        " string enumeration",
        " data generation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "781b2a2c0adfad0d4e9a9fd77940d16995f1f19809bf8f27e52a41385e381aac",
                "md5": "e1f7858e03efaff550a1880454d33ca1",
                "sha256": "738d57c9c08ba5ff9e6d91a31a5964ded4602cf23b351e188092695786197166"
            },
            "downloads": -1,
            "filename": "regex_enumerator-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1f7858e03efaff550a1880454d33ca1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8876,
            "upload_time": "2025-01-04T00:56:15",
            "upload_time_iso_8601": "2025-01-04T00:56:15.818618Z",
            "url": "https://files.pythonhosted.org/packages/78/1b/2a2c0adfad0d4e9a9fd77940d16995f1f19809bf8f27e52a41385e381aac/regex_enumerator-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a2698e996d2771fd78920a86f6fc8b0344d4a8ce16e5e53f8b9c8526316c573",
                "md5": "bbba630e36c70efc3a3dbbc2200236d1",
                "sha256": "37f3e2820556bc265840adbc438318b72f0bddd275672fa7bcde209ee58bc198"
            },
            "downloads": -1,
            "filename": "regex_enumerator-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bbba630e36c70efc3a3dbbc2200236d1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 13381,
            "upload_time": "2025-01-04T00:56:19",
            "upload_time_iso_8601": "2025-01-04T00:56:19.508961Z",
            "url": "https://files.pythonhosted.org/packages/9a/26/98e996d2771fd78920a86f6fc8b0344d4a8ce16e5e53f8b9c8526316c573/regex_enumerator-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-04 00:56:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Buba98",
    "github_project": "regex_enumerator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "regex-enumerator"
}
        
Elapsed time: 2.22369s