An extractor object that yields the groups in the match. Using this extractor rather than the original Regex ensures that the match is not recomputed.
import scala.util.matching.Regex.Groups
val date = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
val text = "The doc spree happened on 2011-07-15."
val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"$month/$day" })
| Supertypes | |
|---|---|
| Self type |
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.2.0/scala/util/matching/Regex$$Groups$.html