Skip to content

Regex library for go implemented using Finite State Machine

Notifications You must be signed in to change notification settings

dropdevrahul/fmsregex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple project to demonstrate usage of Finite State Machines

Note: original credit to rust video on same by tsoding

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
}

About

Regex library for go implemented using Finite State Machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages