import com.github.verbalexpressions.VerbalExpression
import VerbalExpression._
val validUrl = $.startOfLine()
.andThen("http")
.maybe("s")
.andThen("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine()
assert("https://www.google.com" is validUrl)
assert("ftp://home.comcast.net" isNot validUrl)
// VerbalExpressions can be nested within each other
val fraction = $.andThen(".").digits()
val number = $.maybe("-").digits().maybe(fraction)
assert(Seq("3", "-4", "-0.458") forall number.check)
assert(Seq("0.", "hello", "4.3.2") forall number.notMatch)
For more methods, checkout the wiki and the source
Add the following to your build.sbt
:
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases/"
libraryDependency += "com.github.verbalexpressions" %% "scalaverbalexpression" % "1.0.1"