Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bgahagan/scala-regex-interpolation
String interpolation of regex capture groups in scala match statements
https://github.com/bgahagan/scala-regex-interpolation
match regex scala
Last synced: 26 days ago
JSON representation
String interpolation of regex capture groups in scala match statements
- Host: GitHub
- URL: https://github.com/bgahagan/scala-regex-interpolation
- Owner: bgahagan
- License: mit
- Created: 2019-07-22T23:33:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-28T12:38:47.000Z (over 5 years ago)
- Last Synced: 2023-08-06T09:56:46.578Z (over 1 year ago)
- Topics: match, regex, scala
- Language: Scala
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Regex String Interpolation Utility
==================================[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.bgahagan/scala-regex-interpolation_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.bgahagan/scala-regex-interpolation_2.13)
A small library that allows [interpolation](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#interpolated-string-patterns) of regex capture groups in `match` statements.
The nth interpolant (e.g. `$group1`) will match against the nth capture group in the regex.
Example
-------
```
import dev.bgahagan.regex.intrpl._"hello world" match {
case r"(\w+)$group1 (\w+)$group2" =>
println(group2)
}
```Outputs:
```
world
```Design Notes
------------* The regex is parsed and compiled on each `match` invocation.