Skip to content
Regular expression library for Scala
Branch: master
Clone or download
nrinaudo Merge pull request #81 from nrinaudo/update-kantan-sbt
[updates] Update to kantan.sbt 2.4.0
Latest commit a6c0a2c May 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cats/shared/src
core [updates] Update to kantan.sbt 2.4.0 May 15, 2019
docs/src [#76] Update to kantan.codecs 0.4.1-SNAPSHOT May 3, 2018
enumeratum
generic
java8/src
joda-time/src [#72] Add support for literal date formats Feb 23, 2018
laws/shared/src/main
libra/src [#57] Add a libra module Jan 25, 2018
project
refined [#61] Add support for scala.js Feb 9, 2018
scalaz/shared/src [updates] Update to kantan.sbt 2.4.0 May 15, 2019
.gitignore
.jvmopts
.travis.yml
LICENSE
README.md Replace the maven central badge by scaladex. Dec 18, 2016
build.sbt
codecov.yml
version.sbt

README.md

kantan.regex

Build Status codecov Latest version Join the chat at https://gitter.im/nrinaudo/kantan.regex

There are two main use-cases for regular expressions:

  • predicates (does a string match a given pattern?)
  • data extraction (grab whatever matches a given pattern)

Kantan.regex is solely concerned with the second use case, and is meant to make data extraction from strings as painless as possible - you still have to write regular expressions, so still a bit painful, but at least the rest is automated away and checked by the compiler.

Documentation and tutorials are available on the companion site, but for those looking for a few quick examples:

import kantan.regex._
import kantan.regex.implicits._
import kantan.regex.generic._

// Returns an iterator on all parts of str that look like a positive integer
"abc 123 def".evalRegex[Int](rx"\d+")

// Returns an iterator on all parts of str that look like an (x, y) point. Points
// are represented as a Tuple2[Int, Int]
"(1, 2) and then (3, 4)".evalRegex[(Int, Int)](rx"\((\d+), (\d+)\)")

// Declares a new Point case class, lets shapeless work out how to decode for it.
case class Point(x: Int, y: Int)

// Returns an iterator on all parts of str that look like an (x, y) point. Points
// are represented as Point.
"(1, 2) and then (3, 4)".evalRegex[Point](rx"\((\d+), (\d+)\)")

// A somewhat contrived example where the z-coordinate of a point is optional:
"(1, 2) and then (3, 4, 5)".evalRegex[(Int, Int, Option[Int])](rx"\((\d+), (\d+)(?:, (\d+))?\)")

kantan.regex is distributed under the Apache 2.0 License.

You can’t perform that action at this time.