package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)\x1B\[(?:[0-9]{1,3}(?:;[0-9]{1,3})?)?[mGK]`)
var str = `Summary [0m
Accounts:
Name Account ID Title
----------------------------------------------- ------------ -----------------------------------------------
[32maccount-accountType-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-gamma
[32maccount-accountType-e2e-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-gamma
Summary [0m
Accounts:
Name Account ID Title
---------------------------------------------- ------------ ----------------------------------------------
[32maccount-accountType-e2e-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-prod
[32maccount-accountType-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-prod`
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/