Skip to main content

EBR (Easy Bracket Regex) - Simplified regex with bracket notation

Project description

EBR - Easy Bracket Regex

PyPI version License: MIT

EBR (Easy Bracket Regex) is a simplified pattern matching library that makes text extraction intuitive and readable. Instead of complex regex syntax, use simple bracket notation.

Features

  • <|cap|> - Capture text between patterns
  • <|ow|> - Match optional whitespace (zero or more spaces)
  • <|any|> - Match any single character
  • <|esc|X> - Match a specific character X literally

Installation

pip install ebr

Quick Start

from ebr import ebr, capture, capture_all

# Single capture
text = "Hello how are you"
result = ebr(text, "Hello how <|cap|> you")
print(result)  # Output: "are"

# Multiple captures
text = "Hello how are yall"
results = ebr(text, "<|cap|> how <|cap|>")
print(results)  # Output: ['Hello', 'are yall']

# Optional whitespace
text = "Hello            World"
result = capture(text, "Hello<|ow|><|cap|>")
print(result)  # Output: "World"

# Any character wildcard
text = "Hello:World"
result = capture(text, "Hello<|any|><|cap|>")
print(result)  # Output: "World"

# Escape special characters
text = "Hello*World"
result = capture(text, "Hello<|esc|*><|cap|>")
print(result)  # Output: "World"

API Reference

ebr(text: str, pattern: str) -> Union[str, List[str]]

Smart function that returns a single string for one capture group, or a list for multiple capture groups.

capture(text: str, pattern: str) -> str

Extracts the first capture group from text. Returns empty string if no match.

capture_all(text: str, pattern: str) -> List[str]

Extracts all capture groups from text. Returns empty list if no match.

Pattern Syntax

Pattern Description Regex Equivalent
`< cap >`
`< ow >`
`< any >`
`< esc X>`

Examples

Extract data from structured text

from ebr import capture_all

log = "2024-01-15 10:30:45 ERROR User login failed"
parts = capture_all(log, "<|cap|> <|cap|> <|cap|> <|cap|>")
date, time, level, message = parts
print(f"Level: {level}, Message: {message}")

Parse key-value pairs

from ebr import capture

config = "timeout=30"
value = capture(config, "timeout<|ow|>=<|ow|><|cap|>")
print(f"Timeout: {value}")  # Output: "Timeout: 30"

Handle flexible spacing

from ebr import capture

text1 = "HelloWorld"
text2 = "Hello World"
text3 = "Hello            World"

pattern = "Hello<|ow|><|cap|>"
print(capture(text1, pattern))  # Output: "World"
print(capture(text2, pattern))  # Output: "World"
print(capture(text3, pattern))  # Output: "World"

Why EBR?

Traditional regex can be hard to read and write:

import re
result = re.search(r"Hello how (.+?) you", text).group(1)

EBR makes it intuitive:

result = ebr(text, "Hello how <|cap|> you")

Building from Source

git clone https://github.com/Qarvexium/ebr.git
cd ebr
pip install -e .

Requirements

  • Python 3.7+
  • C++17 compatible compiler
  • setuptools

License

MIT License - see LICENSE file for details

Author

Qarvexium

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

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

ebr-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

ebr-1.0.0-cp313-cp313-win_amd64.whl (48.3 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file ebr-1.0.0.tar.gz.

File metadata

  • Download URL: ebr-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ebr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 73412b02abba1d248bdfb39f2dda9c2e7ee156c1f31afb16e1d968a741f3d4d1
MD5 3b663ab264d5d39da80623b12920e5db
BLAKE2b-256 9b300f6eadbbbd1a3c895d3f51a818655e5c1176e78d8a4f24c2519011f76993

See more details on using hashes here.

File details

Details for the file ebr-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ebr-1.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 48.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ebr-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 215e8b2a4bc3d68faa8635d0c4a5940433e45a6e2ea9b175290f41dff7f5b048
MD5 11beb827fa85dcd003af390a577db5b4
BLAKE2b-256 363325c590d98d60d2914ec99dc4c41b4f2595258612dca529dd33e6703b3c32

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