A minimal regex matcher in Scala. This repository is mainly aimed at learning implementations of regular expressions.
Add the following lines to your build.sbt file:
libraryDependencies += "com.github.kmizu" %% "mregex" % "0.1.0"
import com.github.kmizu.mregex._
matches(pattern=”””ab”””, string=“ab”) // true
matches(pattern=”””a|b”””, string=”a”) // true
matches(pattern=”””a|b”””, string=”c”) // false
matches(pattern=”””(a|b)*”””, string=”abbaab”) // true
matches(pattern=”””(a|b)*”””, string=”abaaac”) // false
matches(pattern=”””ab”””, string=“ab”) // true
matches(pattern=”””a|b”””, string=”a”) // true
matches(pattern=”””a|b”””, string=”c”) // false
matches(pattern=”””(a|b)*”””, string=”abbaab”) // true
matches(pattern=”””(a|b)*”””, string=”abaaac”) // false
a is regular expression. Note that a doesn't mean a
itself but any character.
a
b
z
0
9
e1|e2
is regular expression where e1
and e2
are regular expressions:
a|b
a|b|c
e1e2
is regular expression where e1
and e2
are regular expressions:
ab
abc
e*
is regular expression where e
is regular expression:
a*
(a|b)*
e+
is regular expression where e
is regular expression:
a+
(a|b)+
e?
is regular expression where e
is regular expression:
a+
a(b)?c