Last active
October 9, 2015 05:47
-
-
Save dohzya/3448195 to your computer and use it in GitHub Desktop.
Make regexp simple to use
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
import scala.util.matching.Regex | |
object RubyRegex { | |
case class RubyMatcher(rx: Regex) extends AnyVal { // Value Class (no runtime overhead!) | |
def ===(str: String) = rx.findFirstIn(str).isDefined | |
} | |
implicit def Regex2RubyMatcher(rx: Regex) = RubyMatcher(rx) | |
case class RubyMatched(str: String) extends AnyVal { // Value Class (no runtime overhead!) | |
def =~(rx: Regex) = rx.findFirstIn(str).isDefined | |
} | |
implicit def String2RubyMatched(str: String) = RubyMatched(str) | |
} | |
// import RubyRegex._ | |
// println("coucou" =~ "^c".r) // => true | |
// println("coucou" =~ "^ac".r) // => false | |
// println("""^\d+$""".r === "123") // => true | |
// println("""^\d+$""".r === "12a3") // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment