This question already has an answer here:
- Split a string on whitespace in Go? 3 answers
I am parsing an Apache log that I have customised to give me two values only: "time" and "memory" (the values are number of milliseconds and number of bytes) that are both are int64 or float64, but I am using regexp and Go to parse through the file, so when I am matching the contents of the files it return "[]" (empty braces) and is not populating the slice, my code is:
for _, line := range lines {
var buffer bytes.Buffer
buffer.WriteString(`\[0-9]+\s`)
buffer.WriteString(`[0-9]+\s`)
re1, err := regexp.Compile(buffer.String())
if err != nil {
log.Fatalf("regexp: %s", err)
}
result := re1.FindStringSubmatch(line)
fmt.Println(result)
}
When I am printing result, it gives me empty braces and when I am running the whole program, it gives index out of range (which is understandable because result is empty).
My data looks like this:
1040 3952
2849 6832
</div>