package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)\s*
(
(?<type>int(?:\s+long|\s+short)?|double(?:\s+long)?|
long(?:\s+int|\s+double)?|short(?:\s+int)?|float|char)
|
(?<error>\w+|\w+\s*\,)
)
\s+
(?:
(?:
(?:
(?<error>int|double|float|char|long|short|[^,;a-zA-Z_].+?|[^,;]+?(?:\s+\w+?)+)
|
(?<id>[a-zA-Z_][a-zA-Z_0-9]*)
)
(?:\s*\[\s*[1-9]\d*\s*\])*
)
\s*
(?:\,\s*|(?=\;))
)+
\s*\;\s*`)
var str = `int
abv, cde, doub1lel,ded, cto, int1;
float ng23423, _ga45,
astories;
int af , f;
int a, b, c;int short alt ;
long double fgd [ 1 ], [1] , wef ;
char _a[1], fi [
3
] [ 10] [ 4 ] ,g[1];int qw;`
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/