A Kotlin DSL for regular expressions
Provides a Groovy-style builder for regex with safe quantifiers and groups. Readable and extensible.
repositories {
...
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.h0tk3y:regex-dsl:v0.1'
}
literally("text")
that escapes thetext
anyChar()
,digit()
,letter()
,alphaNumeric()
,whitespace()
,wordBoundary()
,wordCharacter()
startOfString()
,endOfString()
optional("text")
andoptional { /* inner regex */ }
,
oneOrMore("text")
and oneOrMore { /* inner regex */ }
,
zeroOrMore("text")
and zeroOrMore { /* inner regex */ }
-
n times ("text")
andn times { /* inner regex */ }
,n timesOrMore ("text")
andn timesOrMore { /* inner regex */ }
,n timesOrLess ("text")
andn timesOrLess { /* inner regex */ }
,n..m times ("text")
andn..m times { /* inner regex */ }
-
index = group { /* inner regex */ }
andmatchGroup(index)
,group("name") { /* inner regex */ }
andmatchGroup("name")
-
anyOf('a', 'b', 'c')
,anyOf('a'..'z', 'A'..'Z', '0'..'9')
,anyOf("abc", "def", "xyz")
,anyOf({ /* inner regex*/ }, { /* inner regex *? })
-
include(anotherRegex)