STRling - Ruby Binding
Part of the STRling Project
![]() |
The Universal Regular Expression Compiler. STRling is a next-generation production-grade syntax designed to make Regex readable, maintainable, and robust. It abstracts the cryptic nature of raw regex strings into a clean, object-oriented, and strictly typed interface that compiles to standard PCRE2 (or native) patterns. |
💿 Installation
gem install strling
Or add to your Gemfile:
gem 'strling'
📦 Usage
Here is how to match a US Phone number (e.g., 555-0199) using STRling in Ruby:
require 'strling'
# Build the phone pattern using the Simply fluent API
# Match: ^(\d{3})[-. ]?(\d{3})[-. ]?(\d{4})$
s = Strling::Simply
phone_pattern = s.merge(
s.start, # Start of line
s.capture(s.digit.times(3)), # 3 digits (area code)
s.may(s.any_of('-', '.', ' ')), # Optional separator
s.capture(s.digit.times(3)), # 3 digits (exchange)
s.may(s.any_of('-', '.', ' ')), # Optional separator
s.capture(s.digit.times(4)), # 4 digits (line number)
s.end # End of line
)
# Compile to regex string and test
regex = Regexp.new(phone_pattern.to_s)
puts regex.match?('555-123-4567') # true
Note: This compiles to the optimized regex:
^(\d{3})[-. ]?(\d{3})[-. ]?(\d{4})$
🚀 Why STRling?
Regular Expressions are powerful but notorious for being "write-only" code. STRling solves this by treating Regex as Software, not a string.
- 🧩 Composability: Regex strings are hard to merge. STRling lets you build reusable components (e.g.,
ip_address,email) and safely compose them into larger patterns without breaking operator precedence or capturing groups. - 🛡️ Type Safety: Catch syntax errors, invalid ranges, and incompatible flags at compile time inside your IDE, not at runtime when your app crashes.
- 🧠 IntelliSense & Autocomplete: Stop memorizing cryptic codes like
(?<=...). Use fluent, self-documenting methods likeSimply.look_behind(...)with full IDE discovery. - 📖 Readability First: Code is read far more often than it is written. STRling patterns describe intent, making them understandable to junior developers and future maintainers instantly.
- 🌍 Polyglot Engine: One mental model, 17 languages. Whether you are writing Rust, Python, or TypeScript, the syntax and behavior remain identical.
🏗️ Architecture
STRling follows a strict compiler pipeline architecture to ensure consistency across all ecosystems:
- Parse:
DSL -> AST(Abstract Syntax Tree)- Converts the human-readable STRling syntax into a structured tree.
- Compile:
AST -> IR(Intermediate Representation)- Transforms the AST into a target-agnostic intermediate representation, optimizing structures like literal sequences.
- Emit:
IR -> Target Regex- Generates the final, optimized regex string for the specific target engine (e.g., PCRE2, JS, Python
re).
- Generates the final, optimized regex string for the specific target engine (e.g., PCRE2, JS, Python
📚 Documentation
- API Reference: Detailed documentation for this binding.
- Project Hub: The main STRling repository.
- Specification: The core grammar and semantic specifications.
🌐 Connect
💖 Support
If you find STRling useful, consider starring the repository and contributing!
