https://github.com/zach-klippenstein/go-typedregexp
typedregexp matches regular expressions into structs.
https://github.com/zach-klippenstein/go-typedregexp
Last synced: 20 days ago
JSON representation
typedregexp matches regular expressions into structs.
- Host: GitHub
- URL: https://github.com/zach-klippenstein/go-typedregexp
- Owner: zach-klippenstein
- License: apache-2.0
- Created: 2016-01-17T20:51:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-20T16:04:47.000Z (over 9 years ago)
- Last Synced: 2025-03-26T21:23:19.111Z (about 1 month ago)
- Language: Go
- Homepage: https://godoc.org/github.com/zach-klippenstein/go-typedregexp
- Size: 24.4 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# typedregexp [](https://travis-ci.org/zach-klippenstein/go-typedregexp) [](https://godoc.org/github.com/zach-klippenstein/go-typedregexp)
`typedregexp` matches regular expressions into structs.
```go
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.](https://godoc.org/github.com/zach-klippenstein/go-typedregexp#pkg-examples)