Created
December 18, 2013 12:43
-
-
Save qerub/8021708 to your computer and use it in GitHub Desktop.
Bringing Perl's (main) regex operators to [Scala] (just for fun)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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