Skip to content

Instantly share code, notes, and snippets.

@qerub
Created December 18, 2013 12:43
Show Gist options
  • Save qerub/8021708 to your computer and use it in GitHub Desktop.
Save qerub/8021708 to your computer and use it in GitHub Desktop.
Bringing Perl's (main) regex operators to [Scala] (just for fun)
implicit class StringExtensions(val _value: String) extends AnyVal {
def =~(r: Regex): Boolean = _value match {
case `r`() => true
case `r`(xs @ _*) => throw new IllegalArgumentException("Regex must not contain captures")
case _ => false
}
def !~(r: Regex): Boolean = !(this =~ r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment