https://github.com/juan-medina/regexp-dsl
expressive regular expressions with a domain specific language written in Kotlin
https://github.com/juan-medina/regexp-dsl
domain-specific-language dsl kotlin regex regex-pattern regexes regexp regexpr regular-expression regular-expressions
Last synced: 8 months ago
JSON representation
expressive regular expressions with a domain specific language written in Kotlin
- Host: GitHub
- URL: https://github.com/juan-medina/regexp-dsl
- Owner: juan-medina
- License: apache-2.0
- Created: 2020-01-01T11:33:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T20:01:23.000Z (over 5 years ago)
- Last Synced: 2025-01-12T23:12:18.338Z (10 months ago)
- Topics: domain-specific-language, dsl, kotlin, regex, regex-pattern, regexes, regexp, regexpr, regular-expression, regular-expressions
- Language: Kotlin
- Homepage: https://juan-medina.github.io/regexp-dsl/
- Size: 797 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RegExp DSL
Expressive Regular Expressions with a Domain Specific Language written in Kotlin
[](https://github.com/juan-medina/regexp-dsl/blob/master/LICENSE)
[](https://juan-medina.github.io/regexp-dsl/)
[](https://travis-ci.com/juan-medina/regexp-dsl)
[](https://jitpack.io/#juan-medina/regexp-dsl)
## Info
RegExp DSL is a library that allow the creation an usage of regular expressions, written in Kotlin, via a Domain Specif Language tha aims to be expressive. The overall idea is to make expressions easy to understand, modify and update.
## Installation
### Maven
```xml
jitpack.io
https://jitpack.io
com.github.juan-medina
regexp-dsl
0.1.0-SNAPSHOT
```
### Gradle Groovy
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.juan-medina:regexp-dsl:0.1.0-SNAPSHOT'
}
```
### Gradle Kotlin
```kotlin
repositories {
maven {
setUrl("https://jitpack.io")
}
}
dependencies {
implementation("com.github.juan-medina:regexp-dsl:0.1.0-SNAPSHOT")
}
```
## Usage
### Generating a RegExp
```kotlin
import com.medina.juan.regexp.dsl.regexp
fun main() {
val reg = regexp {
literal("foo")
maybe("bar")
zeroOrMore{
character()
}
}
println(reg.matches("foo")) // true
println(reg.matches("fooooo")) // true
println(reg.matches("foobar")) // true
println(reg.matches("foobarrrr")) // true
println(reg.matches("bar")) // false
}
```
### Generating a pattern
```kotlin
import com.medina.juan.regexp.dsl.pattern
fun main() {
val ptn = pattern {
literal("foo")
maybe("bar")
zeroOrMore{
character()
}
}
println(ptn) // foo(?:bar)?.*
}
```
### JSR 380 Validations
```kotlin
class ValidateName : DslValidator({
literal("foo")
maybe("bar")
zeroOrMore {
character()
}
})
@Constraint(validatedBy = [ValidateName::class])
annotation class ValidName(
val message: String = "name is not valid",
val groups: Array> = [],
val payload: Array> = []
)
data class Person(@field:ValidName val name: String)
```
## License
```text
Copyright (C) 2020 Juan Medina
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```