Skip to content

mkh-user/enhex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnhEx: Enhanced Expression

Regex, Enhanced for Readability.

PyPI - Downloads NPM - Downloads Crates.io - Downloads

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: ✅ enhex at PyPI with native extension (PyO3)
  • JavaScript: ✅ enhexjs at 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() + end

Regex Output

^[\w\.-]+@[\w-]+\.[a-z]{2,10}$

Same logic, but you can actually read the first one.


Installation

Python

pip install enhex

Rust

cargo install enhex-core

JavaScript / TypeScript

npm install enhexjs

CLI (via Python)

pip install enhex
enhex compile "start + one_or_more(digit) + end"
# Output: ^\d+$

Usage

Python Library

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 Pakcage

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 Crate

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 version

Syntax

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() + end

Development

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.md

Roadmap

  • Language specification
  • Rust core engine + WASM
  • Python binding
  • CLI tool
  • 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.1

Rules:

  • 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.

About

A more safe, readable, and maintainable way to use Regular Expressions

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors