Skip to main content

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

Release files for ebr 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ebr 1.0.1
File Size Uploaded
ebr-1.0.1.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ebr 1.0.1
File Interpreter ABI Platform
ebr-1.0.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details

Total release size: 60.7 kB

Release files / ebr-1.0.1.tar.gz

Download URL ebr-1.0.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c587ba233c04660800f0639999302e84843e618a588658e62f3118ddea49f083
BLAKE2b-256 checksum
How to use checksums
632a4ab93412b07f2a05e3e8676553e2b6340f9d5b878dbb1204a405c4666ef9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / ebr-1.0.1-cp313-cp313-win_amd64.whl

Download URL ebr-1.0.1-cp313-cp313-win_amd64.whl
Size 48.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
47115f60fae6521de37fd2f8411d92e2cb7127b7e3e5ad3cb86b18aff1090484
BLAKE2b-256 checksum
How to use checksums
75d5ddba2434dc6aa001b0100bbe5b61e33f3de9a600c81050895b311c827663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page