package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)`)
var str = `## Should Pass
build: test
chore(topic): descriptoin
chore(junk): that's better
¯\_(ツ)_/¯: descriptoin
feat: some with-hyphen
### should pass with breaking change
feat!: monkeys are the best for animal testing
build(three)!: test
Merge words
### Failed to match test
Merge
monkey(dog): no
junk
### Partials that should fail
build(with colon): must include colon. <<< fails number four
build(one) <<< must have descriptoin and must have colon
feat!:dogs are better for animal testing << give me your whitespace
build <<< thould fail, not allowed end of line
build(: <<< should fail
build(words):noSPace <<< should fail
build(two)asdfadfadasdf_this is a failure
build(<> : dda!sd): test <<< should this fail?
build(example:module)!: test subject <<< that should fail too
¯\_(ツ)_/¯[type]:descriptoin
`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/