enhexjs
v0.4.0
Published
EnhEx - Enhanced Expression. Write readable patterns, get Regex.
Downloads
426
Maintainers
Readme
EnhEx: Enhanced Expression
Regex, Enhanced for Readability.
EnhEx is a simple, readable language for writing regular expressions. Write patterns like sentences. Get standard Regex output. Use it anywhere — Python, JavaScript, Rust, CLI, browser.
Why EnhEx?
Regex is powerful but painfully unreadable. After a few months, even your own patterns look like alien code.
EnhEx fixes this:
- Write patterns in a clean, human-readable syntax
- Compile to standard Regex that works everywhere
- One core, written in Rust, compiled to WASM or native extension — runs identically in every language
Language Support Status:
- Rust: ✅ Native
- Python: ✅
enhexat PyPI with native extension (PyO3) - JavaScript: ✅
enhexjsat NPM with WASM (WASM BindGen)
Quick Example
EnhEx Input
start + one_or_more(word_char | dot | dash) + "@" + one_or_more(word_char | dash) + dot + tld() + endRegex Output
^[\w\.-]+@[\w-]+\.[a-z]{2,10}$Same logic, but you can actually read the first one.
Installation
Python
pip install enhexRust
cargo install enhex-coreJavaScript / TypeScript
npm install enhexjsCLI (via Python)
pip install enhex
enhex compile "start + one_or_more(digit) + end"
# Output: ^\d+$Usage
Python
import enhex as ex
# Compile a pattern string
pattern = ex.compile('start + one_or_more(digit) + end')
# Compile from a .enhex file
phone_pattern = ex.compile_file('phone.enhex')
# Use with standard re module
import re
if re.match(pattern, "367812009"):
print("Valid number!")JavaScript
import { enhex, compile, compileRegExp } from 'enhexjs';
// or compile('start + one_or_more(digit) + end'):
const pattern = enhex`start + one_or_more(digit) + end`;
const regex = new RegExp(pattern);
if (regex.test('12345')) {
console.log('Only digits!');
}
// Or automatic RegExp creation:
const re = compileRegExp('start + one_or_more(digit) + end');
if (re.test('12345')) {
console.log('Only digits!');
}
Rust
use enhex_core::compile;
let pattern = compile("start + one_or_more(digit) + end").unwrap();
let re = regex::Regex::new(&pattern).unwrap();
assert!(re.is_match("12345"));CLI
# Compile a pattern string
enhex compile 'start + exactly(10, digit) + end'
# Compile a .enhex file
enhex compile phone.enhex
# Show version
enhex versionSyntax
See EnhEx Language Specification for complete syntax.
File Format
EnhEx patterns are stored in .enhex files:
email.enhex:
start + one_or_more(word_char | dot | dash) + "@" + one_or_more(word_char | dash) + "." + tld() + endDevelopment
Project Structure
enhex/
├── core/ # Rust core engine
├── bindings/
│ ├── python/ # Python package
│ └── js/ # JavaScript/TypeScript package
├── examples/ # Example .enhex patterns
├── vscode/ # VSCode extension (coming soon)
├── playground/ # Web playground (coming soon)
├── SPEC.md # Full language specification
└── README.mdRoadmap
- [x] Language specification
- [x] Rust core engine + WASM
- [x] Python binding
- [x] CLI tool
- [x] JavaScript/TypeScript binding
- [ ] VSCode extension (syntax highlighting + live preview)
- [ ] Web playground
Versioning Policy
EnhEx uses a separated versioning for core and each bindings, for example this list maybe current last versions:
core-v0.2
py-v0.5
js-v0.3.1Rules:
- Each core version change results in the same type of version increment across all bindings. (
core-v0.4 -> core-v0.5:py-v0.6 -> py-v0.7,js-v0.5 -> js-v0.6) - Each binding can have a patch or minor version increment (the major version is only changed by the core), and this change has no effect on the core version or other bindings.
The changelog for the core and each binding is available in a separate file; see CHANGELOG.md for an overview.
License
MIT © Mahan Khalili
RegEx, Enhanced.
