https://github.com/dropdevrahul/fmsregex
Regex library for go implemented using Finite State Machine
https://github.com/dropdevrahul/fmsregex
Last synced: 3 months ago
JSON representation
Regex library for go implemented using Finite State Machine
- Host: GitHub
- URL: https://github.com/dropdevrahul/fmsregex
- Owner: dropdevrahul
- Created: 2023-01-25T17:55:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-27T11:12:58.000Z (about 3 years ago)
- Last Synced: 2024-06-20T11:58:57.390Z (over 1 year ago)
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Simple project to demonstrate usage of Finite State Machines
*Note*: original credit to rust video on same by [tsoding](https://www.youtube.com/watch?v=MH56D5M9xSQ&t=6206s&ab_channel=TsodingDaily)
Uses finite state machine to implement regex in Golang.
Currently supports '$' and '.' in usual sens of regex that is $ means regex match should end and . means any printable character can be present (only 1 character)
```
package main
import (
"github.com/dropdevrahul/fmsregex/fmsregex"
)
func main() {
f := fmsregex.FSM{}
f.Compile("abc.g$")
res := f.Match("abceg") // true
res = f.Match("abcfg") // true
res = f.Match("abcega") // false
f.Compile("abcg")
res = f.Match("abcgagagdsajd") // true
f.Compile("abcg$")
res = f.Match("abcgagagdsajd") // false
f.Compile("abc[0-9]$")
res = f.Match("abc5") // true
f.Compile("abc[A-Z]$")
res = f.Match("abcG") // true
f.Compile("abc[xyz]$")
res = f.Match("abcy") // true
}
```