package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`\[code\]([\s\S]+)\[/code\]|\[title (.+)\]`)
var str = ` [chapter Introduction]
[section First program]
Java is pretty cool, **we love it**, let's learn.
Use the ::javacc:: to compile stuff.
[title C# is also cool]
bla bla
[code]
some java code in here
[/code]`
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/