Skip to content

Imaginatio/REL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REL, a Regular Expression composition Library

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 ~ $

Features

  • 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

Usage and downloads

3 ways to use the library:

Documentation

License

Copyright © 2012 Imaginatio SAS

REL is released under the Creative Commons BY-NC-SA 4.0 International License.

Authors

REL was developed at Imaginatio for project Splayce by:

Contributors:

  • Guillaume Vauvert (@gvauvert) designed the TrackString algorithm