Java Stack Trace Line in GO
Matches a single Java stack trace frame line.
Try it in the GO tester →Pattern
regexGO
^\s*at\s+([\w$.]+)\(([^)]+)\)$ (flags: gm)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?m)^\s*at\s+([\w$.]+)\(([^)]+)\)$`)
input := ` at com.example.MyClass.method(MyClass.java:42)`
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
`^\s*at\s+` matches the indent and 'at' keyword. `([\w$.]+)` captures the fully-qualified method. `\(([^)]+)\)$` captures the source location.
Examples
Input
at com.example.MyClass.method(MyClass.java:42)Matches
at com.example.MyClass.method(MyClass.java:42)