Skip to content

Commit 96a30fc

Browse files
authored
Updated README.md
1 parent ca9a0c4 commit 96a30fc

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,56 @@ Regular expression tools for Kotlin developers.
55

66
## RegexBuilder
77

8-
`RegexBuilder` is a class for building regular expressions in a more human-readable way using a fluent API. It offers a number of benefits over using raw regex syntax in strings:
8+
`RegexBuilder` is a class for building regular expressions in a more human-readable way using a lightweight, powerful API. It offers a lot of benefits over using raw regex syntax in strings:
99

1010
- No knowledge of regular expression syntax is required: just use simple, intuitively-named classes and methods.
1111
- Code is easier to read, understand and maintain.
1212
- Code is safer and far less prone to regular expression syntax errors and programmer errors.
1313

1414
It is fully documented in the [project wiki](https://github.com/markwhitaker/RegexToolbox.kt/wiki).
1515

16+
## New in version 2.0
17+
18+
### New builder syntax
19+
20+
Version 2.0 introduces a simplified [type-safe builder syntax](https://kotlinlang.org/docs/reference/type-safe-builders.html) for cleaner, less error-prone and more Kotliny code. Go from this:
21+
22+
```kotlin
23+
val regex = RegexBuilder()
24+
.startGroup()
25+
.text()
26+
.digit()
27+
.buildRegex() // ERROR: forgot to call endGroup()
28+
```
29+
30+
to this:
31+
32+
```kotlin
33+
val regex = regex {
34+
group {
35+
text()
36+
digit()
37+
} // Yay! Can't forget to close the group
38+
} // Yay! No need to call buildRegex()
39+
```
40+
41+
The old syntax is still supported if that's your preference (and for consistency with the sibling projects listed at the bottom of the page).
42+
43+
### Quantifiers
44+
45+
`RegexQuantifier` is now a sealed class and its methods have become objects or classes. The old syntax is still supported but deprecated and will be removed in a future version.
46+
47+
|Old syntax|becomes|
48+
|---|---|
49+
|`RegexQuantifier.zeroOrOne()`|`RegexQuantifier.ZeroOrOne`|
50+
|`RegexQuantifier.zeroOrMore()`|`RegexQuantifier.ZeroOrMore`|
51+
|`RegexQuantifier.oneOrMore()`|`RegexQuantifier.OneOrMore`|
52+
|`RegexQuantifier.exactly(1)`|`RegexQuantifier.Exactly(1)`|
53+
|`RegexQuantifier.atLeast(1)`|`RegexQuantifier.AtLeast(1)`|
54+
|`RegexQuantifier.noMoreThan(1)`|`RegexQuantifier.NoMoreThan(1)`|
55+
|`RegexQuantifier.between(1,2)`|`RegexQuantifier.Between(1,2)`|
56+
|`[quantifier].butAsFewAsPossible()`|`[quantifier].butAsFewAsPossible`|
57+
1658
## Usage (Gradle)
1759

1860
Replace `x.y.z` with the latest version.

0 commit comments

Comments
 (0)