Skip to content

zach-klippenstein/go-typedregexp

Repository files navigation

typedregexp Build Status GoDoc

typedregexp matches regular expressions into structs.

import (
	"fmt"
	"log"

	"github.com/zach-klippenstein/go-typedregexp"
)

type Values struct {
	Name string
	Age  string
}

func main() {
	re, _ := typedregexp.Compile("Hi, I'm {{.Name}}. I'm {{.Age}} years old!|I'm {{.Name}}, I'm {{.Age}}.", Values{
		Name: `\w+`,
		Age:  `\d+`,
	})

	var values Values
	if re.Find("Hi, I'm Sam. I'm 20 years old!", &values) {
		fmt.Printf("%+v", values)
	} else {
		fmt.Println("No match.")
	}
}

Prints {Name:Sam Age:20}.

See the godoc for more examples.

About

typedregexp matches regular expressions into structs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages