Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.