bgahagan / scala-regex-interpolation   1.0.0

MIT License GitHub

String interpolation of regex capture groups in scala match statements

Scala versions: 2.13 2.12

Regex String Interpolation Utility

Maven Central

A small library that allows interpolation 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.