Skip to content

Commit f26eb8a

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents ed62ebc + 773c7f0 commit f26eb8a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# regex-dsl
2+
A Kotlin DSL for regular expressions
3+
4+
Provides a Groovy-style builder for regex
5+
6+
val r = regex {
7+
group("prefix") {
8+
literally("+")
9+
oneOrMore { digit(); letter() }
10+
}
11+
3 times { digit() }
12+
literally(";")
13+
matchGroup("prefix")
14+
}
15+
16+
Currently supports:
17+
18+
* `literally("text")` that escapes the `text`
19+
* `anyChar()`, `digit()`, `letter()`, `alphaNumeric()`, `whitespace()`, `wordBoundary()`, `wordCharacter()`
20+
* `startOfString()`, `endOfString()`
21+
* `optional("text")` and `optional { /* inner regex */ }`,
22+
23+
`oneOrMore("text")` and `oneOrMore { /* inner regex */ }`,
24+
25+
`zeroOrMore("text")` and `zeroOrMore { /* inner regex */ }`
26+
27+
* `n times ("text")` and `n times { /* inner regex */ }`,
28+
29+
`n timesOrMore ("text")` and `n timesOrMore { /* inner regex */ }`,
30+
31+
`n timesOrLess ("text")` and `n timesOrLess { /* inner regex */ }`,
32+
33+
`n..m times ("text")` and `n..m times { /* inner regex */ }`
34+
35+
* `index = group { /* inner regex */ }` and `matchGroup(index)`,
36+
37+
`group("name") { /* inner regex */ }` and `matchGroup("name")`
38+
39+
* `anyOf('a', 'b', 'c')`,
40+
41+
`anyOf('a'..'z', 'A'..'Z', '0'..'9')`,
42+
43+
`anyOf("abc", "def", "xyz")`,
44+
45+
`anyOf({ /* inner regex*/ }, { /* inner regex *? })`
46+
47+
* `include(anotherRegex)`

0 commit comments

Comments
 (0)