Markdown Image in GO
Matches Markdown image syntax .
Try it in the GO tester →Pattern
regexGO
!\[([^\]]*)\]\(([^)]+)\) (flags: g)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`!\[([^\]]*)\]\(([^)]+)\)`)
input := ``
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
How the pattern works
`!\[([^\]]*)\]` captures the alt text inside brackets. `\(([^)]+)\)` captures the URL in parentheses.
Examples
Input
Matches

Input
 and Matches
