REL is a Scala library for people dealing with complex, modular regular expressions. It defines a DSL with most of the operators you already know and love. This allows you to isolate portions of your regex for easier testing and reuse.
Consider the following YYYY-MM-DD date regex: ^(?:19|20)\d\d([- /.])(?:0[1-9]|1[012])\1(?:0[1-9]|[12]\d|3[01])$
.
It is a bit more readable and reusable expressed like this:
import fr.splayce.rel._
import Implicits._
val sep = "[- /.]" \ "sep" // group named "sep"
val year = ("19" | "20") ~ """\d\d""" // ~ is concatenation
val month = "0[1-9]" | "1[012]"
val day = "0[1-9]" | "[12]\\d" | "3[01]"
val dateYMD = ^ ~ year ~ sep ~ month ~ !sep ~ day ~ $
val dateMDY = ^ ~ month ~ sep ~ day ~ !sep ~ year ~ $
- A familiar, regex-like syntax
- Powerful extractors for scala Pattern Matching
- Bundled matchers for frequently-used utilities like dates
- Tree-rewriting utilities and Flavors to use your regexes in other languages
- Bundled cleaners to clean your input and further simplify your regexes
3 ways to use the library:
- download the source from github and build the library with SBT
- download the latest binary release
- use our public Maven repository
Copyright ยฉ 2012 Imaginatio SAS
REL is released under the Creative Commons BY-NC-SA 4.0 International License.
REL was developed at Imaginatio for project Splayce by:
- Adrien Lavoillotte (@instanceofme)
- Julien Martin
Contributors:
- Guillaume Vauvert (@gvauvert) designed the
TrackString
algorithm