T-Regex
A fluent, type-safe Kotlin DSL for building, composing, and testing Regular Expressions.
Tame the chaos of regular expressions. Write readable Kotlin code instead of cryptic string soup. Get compile-time safety and type-safe data extraction without sacrificing the power of the underlying regex engine.
Documentation ยท GitHub Releases
Contents
Quick start
1. Library
Add the dependency to your project:
kotlin
dependencies {
implementation("uk.co.developmentanddinosaurs:tregex-core:<version>")
}
2. Usage
Build regular expressions using the builder DSL.
kotlin
import uk.co.developmentanddinosaurs.tregex.TRegex
val pattern = TRegex {
literally("hello world")
}
// Access the compiled pattern
println(pattern.pattern) // "hello world"
// Evaluate against inputs
pattern.matches("hello world") // true
Why T-Regex?
- Readable: Replace write-only syntax like
^[a-zA-Z0-9_\-\.]+$with semantic blocks likeanyCharOf { letter() or digit() }. - No boolean blindness: Strict separation of concepts instead of parameter flags (e.g.,
oneOrMoreLazily()instead ofoneOrMore(greedy = false)). - Cross-platform safe: Emits universally compatible regex strings without relying on engine-specific hacks like
\Q...\E. - Composable: Extract common regex fragments into reusable Kotlin functions and variables.
Building
bash
# Build everything and run all verification checks
./gradlew check
# Run the test suite (Kotest BDD)
./gradlew test
๐ License
MIT License. Built with ๐ฆ by the Development and Dinosaurs community.