Ah! My bad. I misread the docs - "result" is the input, while the "n" indexes are actually the values of the submatches, not the indexes. I still think it's confusing, but makes more sense when I write it like this: https://go.dev/play/p/SHl_aSU3kPZ
On Thursday 14 December 2023 at 09:06:00 UTC Brian Candler wrote: > [a:b] gives you the elements from a to b-1 inclusive. So if you want the > pair at position x, it has to be [x:x+2] > > https://go.dev/play/p/3nvEfOjdfnj > > On Thursday 14 December 2023 at 08:38:57 UTC Peter Galbavy wrote: > >> I noticed today that the regexp docs read: >> >> If 'Index' is present, matches and submatches are identified by byte >> index pairs within the input string: result[2*n:2*n+2] identifies the >> indexes of the nth submatch. >> >> I think that should be result[2*n:2*n+1] - at least in my code that's how >> it is working. >> >> If I'm right, happy to raise a doc bug, but never done that, so not sure >> how - for a one digit change? >> >> Peter >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d67d1a02-e919-4118-9718-012e6497814cn%40googlegroups.com.