repoet


Namerepoet JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/Dawnfz-Lenfeng/repoet
SummaryWrite regular expressions like poetry in Python - transform cryptic regex into elegant, readable patterns
upload_time2024-11-14 14:36:24
maintainerNone
docs_urlNone
authorDawnfz-Lenfeng
requires_python>=3.7
licenseMIT
keywords regex regular expression pattern matching readable
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RePoet: Write Regular Expressions Like Poetry in Python

[![PyPI version](https://badge.fury.io/py/repoet.svg)](https://badge.fury.io/py/repoet)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

🎯 Transform regex into poetry! Write regular expressions as elegantly as writing verses.

## ✨ Highlights

```python
from repoet import op

# Traditional regex (cryptic spell)
date_regex = r"^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$"

# With RePoet (elegant verse)
date = op.seq(
    op.begin,
    op.group(op.digit * 4, name="year") + "-",
    op.group(op.digit * 2, name="month") + "-",
    op.group(op.digit * 2, name="day"),
    op.end
)

match = date.match("2024-03-01")
print(match.group("year"))   # "2024"
print(match.group("month"))  # "03"
print(match.group("day"))    # "01"
```

## 🚀 Why RePoet?

- **🎭 Full Re API Compatibility** - All `re` module features are supported
- **🎨 Operator Magic** - Use `+`, `|`, `*` to compose patterns naturally
- **📝 Multiple Styles** - Choose between operator style or functional style
- **🛡️ Type-Safe** - Full type hints for better IDE support
- **🎯 Zero Learning Curve** - If you know regex, you know RePoet

## 💫 Quick Start

```bash
pip install repoet
```

## 📖 Core Concepts

### Pattern Composition

```python
from repoet import op

# Using operators
pattern = op.digit + op.word + op.space    # \d\w+\s
pattern = op.digit | op.word               # (?:\d|\w+)
pattern = op.digit * 3                     # \d{3}

# Using functions
pattern = op.seq(op.digit, op.word, op.space)
pattern = op.alt(op.digit, op.word)
pattern = op.times(3)(op.digit)
```

### Named Groups & Captures

```python
# Match phone numbers with named groups
phone = op.seq(
    op.maybe("+"),
    op.group(op.digit * 2, "country"),
    " ",
    op.group(op.digit * 3, "area"),
    "-",
    op.group(op.digit * 4, "number")
)

match = phone.match("+86 123-4567")
print(match.group("country"))  # "86"
print(match.group("number"))   # "4567"
```

### Advanced Features

```python
# Lookarounds
price = op.behind("$") + op.digit * 2      # (?<=\$)\d{2}
not_end = op.word + op.not_ahead(op.end)   # \w+(?!$)

# Character Classes
username = op.some(op.anyof("a-zA-Z0-9_"))  # [a-zA-Z0-9_]+
not_digit = op.exclude("0-9")               # [^0-9]

# Quantifiers
optional = op.maybe("s")                    # s?
one_plus = op.some(op.letter)               # \w+
any_amount = op.mightsome(op.space)         # \s*
```

## 🎯 Pattern API

RePoet patterns support all standard `re` module methods:

```python
pattern = op.word + "@" + op.word

# All re module methods are available
pattern.match(string)
pattern.search(string)
pattern.findall(string)
pattern.finditer(string)
pattern.sub(repl, string)
pattern.split(string)
```

## 📚 More Examples

### URL Parser
```python
url = op.seq(
    op.group(op.alt("http", "https"), "protocol"),
    "://",
    op.group(op.some(op.anyof("a-z0-9.-")), "domain"),
    op.group(op.mightsome(op.anyof("/a-z0-9.-")), "path")
)
```

### Date Validator
```python
date = (op.digit * 4) + "-" + \
       (op.digit * 2) + "-" + \
       (op.digit * 2)
```

## 🤝 Contributing

Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests

## 📜 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

⭐️ If you find RePoet useful, please star it on GitHub! ⭐️

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Dawnfz-Lenfeng/repoet",
    "name": "repoet",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "regex, regular expression, pattern matching, readable",
    "author": "Dawnfz-Lenfeng",
    "author_email": "2912706234@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/b6/60/de5f69afdd0817d67472a0e86e83bcb16b1dc79fe2b4e910c0e4b6f60deb/repoet-0.1.2.tar.gz",
    "platform": null,
    "description": "# RePoet: Write Regular Expressions Like Poetry in Python\n\n[![PyPI version](https://badge.fury.io/py/repoet.svg)](https://badge.fury.io/py/repoet)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\ud83c\udfaf Transform regex into poetry! Write regular expressions as elegantly as writing verses.\n\n## \u2728 Highlights\n\n```python\nfrom repoet import op\n\n# Traditional regex (cryptic spell)\ndate_regex = r\"^(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})$\"\n\n# With RePoet (elegant verse)\ndate = op.seq(\n    op.begin,\n    op.group(op.digit * 4, name=\"year\") + \"-\",\n    op.group(op.digit * 2, name=\"month\") + \"-\",\n    op.group(op.digit * 2, name=\"day\"),\n    op.end\n)\n\nmatch = date.match(\"2024-03-01\")\nprint(match.group(\"year\"))   # \"2024\"\nprint(match.group(\"month\"))  # \"03\"\nprint(match.group(\"day\"))    # \"01\"\n```\n\n## \ud83d\ude80 Why RePoet?\n\n- **\ud83c\udfad Full Re API Compatibility** - All `re` module features are supported\n- **\ud83c\udfa8 Operator Magic** - Use `+`, `|`, `*` to compose patterns naturally\n- **\ud83d\udcdd Multiple Styles** - Choose between operator style or functional style\n- **\ud83d\udee1\ufe0f Type-Safe** - Full type hints for better IDE support\n- **\ud83c\udfaf Zero Learning Curve** - If you know regex, you know RePoet\n\n## \ud83d\udcab Quick Start\n\n```bash\npip install repoet\n```\n\n## \ud83d\udcd6 Core Concepts\n\n### Pattern Composition\n\n```python\nfrom repoet import op\n\n# Using operators\npattern = op.digit + op.word + op.space    # \\d\\w+\\s\npattern = op.digit | op.word               # (?:\\d|\\w+)\npattern = op.digit * 3                     # \\d{3}\n\n# Using functions\npattern = op.seq(op.digit, op.word, op.space)\npattern = op.alt(op.digit, op.word)\npattern = op.times(3)(op.digit)\n```\n\n### Named Groups & Captures\n\n```python\n# Match phone numbers with named groups\nphone = op.seq(\n    op.maybe(\"+\"),\n    op.group(op.digit * 2, \"country\"),\n    \" \",\n    op.group(op.digit * 3, \"area\"),\n    \"-\",\n    op.group(op.digit * 4, \"number\")\n)\n\nmatch = phone.match(\"+86 123-4567\")\nprint(match.group(\"country\"))  # \"86\"\nprint(match.group(\"number\"))   # \"4567\"\n```\n\n### Advanced Features\n\n```python\n# Lookarounds\nprice = op.behind(\"$\") + op.digit * 2      # (?<=\\$)\\d{2}\nnot_end = op.word + op.not_ahead(op.end)   # \\w+(?!$)\n\n# Character Classes\nusername = op.some(op.anyof(\"a-zA-Z0-9_\"))  # [a-zA-Z0-9_]+\nnot_digit = op.exclude(\"0-9\")               # [^0-9]\n\n# Quantifiers\noptional = op.maybe(\"s\")                    # s?\none_plus = op.some(op.letter)               # \\w+\nany_amount = op.mightsome(op.space)         # \\s*\n```\n\n## \ud83c\udfaf Pattern API\n\nRePoet patterns support all standard `re` module methods:\n\n```python\npattern = op.word + \"@\" + op.word\n\n# All re module methods are available\npattern.match(string)\npattern.search(string)\npattern.findall(string)\npattern.finditer(string)\npattern.sub(repl, string)\npattern.split(string)\n```\n\n## \ud83d\udcda More Examples\n\n### URL Parser\n```python\nurl = op.seq(\n    op.group(op.alt(\"http\", \"https\"), \"protocol\"),\n    \"://\",\n    op.group(op.some(op.anyof(\"a-z0-9.-\")), \"domain\"),\n    op.group(op.mightsome(op.anyof(\"/a-z0-9.-\")), \"path\")\n)\n```\n\n### Date Validator\n```python\ndate = (op.digit * 4) + \"-\" + \\\n       (op.digit * 2) + \"-\" + \\\n       (op.digit * 2)\n```\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Feel free to:\n- Report bugs\n- Suggest features\n- Submit pull requests\n\n## \ud83d\udcdc License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n\u2b50\ufe0f If you find RePoet useful, please star it on GitHub! \u2b50\ufe0f\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Write regular expressions like poetry in Python - transform cryptic regex into elegant, readable patterns",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/Dawnfz-Lenfeng/repoet/issues",
        "Homepage": "https://github.com/Dawnfz-Lenfeng/repoet"
    },
    "split_keywords": [
        "regex",
        " regular expression",
        " pattern matching",
        " readable"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "591676fa51489641d33f636358fe0561484336b077d8dee3bf15c0a2ed838b9f",
                "md5": "15b8c9af5ddc16cfc091c6eda9968506",
                "sha256": "df7f466e9bbad69785382b6ee2201fc68303930f56556d0c57f3f03b6c52e7f0"
            },
            "downloads": -1,
            "filename": "repoet-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "15b8c9af5ddc16cfc091c6eda9968506",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7059,
            "upload_time": "2024-11-14T14:36:22",
            "upload_time_iso_8601": "2024-11-14T14:36:22.581810Z",
            "url": "https://files.pythonhosted.org/packages/59/16/76fa51489641d33f636358fe0561484336b077d8dee3bf15c0a2ed838b9f/repoet-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b660de5f69afdd0817d67472a0e86e83bcb16b1dc79fe2b4e910c0e4b6f60deb",
                "md5": "1ee357899d866a0366bb5d318efdd256",
                "sha256": "cc7692e7f6c3f66337c4d1da98a4a65566a8a1fb555e0063c17db8e380944937"
            },
            "downloads": -1,
            "filename": "repoet-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1ee357899d866a0366bb5d318efdd256",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7774,
            "upload_time": "2024-11-14T14:36:24",
            "upload_time_iso_8601": "2024-11-14T14:36:24.200694Z",
            "url": "https://files.pythonhosted.org/packages/b6/60/de5f69afdd0817d67472a0e86e83bcb16b1dc79fe2b4e910c0e4b6f60deb/repoet-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-14 14:36:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Dawnfz-Lenfeng",
    "github_project": "repoet",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "repoet"
}
        
Elapsed time: 0.78488s