This is simple VM regex engine written in Go.
This engine may not be practical as I just wrote this to learn how the dfa engine works.
The engine supports the following metacharacters.
Metacharacter | Desciption | Examples |
---|---|---|
. | Matches any characters. | . = a, b, c |
* | Matches 0 or more repetitions of a pattern. | a* = a, aaa... |
+ | Matches 1 or more repetitions of a pattern. | (abc)+ = abc, abcabc, abcabcabc... |
? | Matches 0 or 1 repetitions of a pattern. | Apple? = Appl, Apple |
| | Match any of the left and right patterns.(like the Boolean OR) | a|b|c = a, b, c |
re := vmregex.Compile("(a|b)c*")
re.Match("acccc") // => true
package main
import (
"fmt"
"github.com/8ayac/vm-regex-engine/vmregex"
)
func main() {
regex := "piyo(o*)"
re := vmregex.Compile(regex)
for _, s := range []string{"piyo", "piyoooo", "piy0"} {
if re.Match(s) {
fmt.Printf("%s\t=> matched.\n", s)
} else {
fmt.Printf("%s\t=> NOT matched.\n", s)
}
}
}
$ go run main.go
piyo => matched.
piyoooo => matched.
piy0 => NOT matched.
$ go get -u github.com/8ayac/vm-regex-engine