package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)[^[:graph:]*](?#Do not match on any visible character)
\K\*(?#Reset starting point and then match on a *)
([[:alpha:].,\ ]+(?:\*{2}[[:alpha:].,\ ]+\*{2}?\ ?)?)(*COMMIT)
\*\ ?(?#Match on ending * then stop matching with COMMIT)`)
var str = `This text is not italic.
*This text is italic.*
This text is *partially* italic
This text has *two* *italic* bits
**bold text (not italic)**
**bold text with *italic* **
**part bold,** *part italic*
*italic text **with bold** *
*italic* **bold** *italic* **bold**
*invalid markdown (do not parse)**
random * asterisk`
var substitution = "<i>$1</i> "
fmt.Println(re.ReplaceAllString(str, substitution))
}
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/