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")

Requirements

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

License

MIT License - see LICENSE file for details

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.1.tar.gz (12.5 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.1-cp313-cp313-win_amd64.whl (48.2 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

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

File metadata

  • Download URL: ebr-1.0.1.tar.gz
  • Upload date:
  • Size: 12.5 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.1.tar.gz
Algorithm Hash digest
SHA256 c587ba233c04660800f0639999302e84843e618a588658e62f3118ddea49f083
MD5 8f58bd8934263cf388c6e9a39b2c81ec
BLAKE2b-256 632a4ab93412b07f2a05e3e8676553e2b6340f9d5b878dbb1204a405c4666ef9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ebr-1.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 48.2 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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 47115f60fae6521de37fd2f8411d92e2cb7127b7e3e5ad3cb86b18aff1090484
MD5 ae0dc1b8d645faaefa1409ba2a2389fa
BLAKE2b-256 75d5ddba2434dc6aa001b0100bbe5b61e33f3de9a600c81050895b311c827663

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