0

We all know what they say about regular expressions ... two problems, and what not. Today, I was poking around with regular expressions in Go and I noticed something kind of strange.

Let's say we have this regular expression:

(..).*\1

If we break this down, step by step it works out to something like:

() / This is a group of things. 
.  / Any character
.  / Any character again 
.  / ... and again
*  / Zero or more matches
\1 / Something that matches the first group in the ()

But here's the thing, if you put this in Go you end up getting this kind of error:

# command-line-arguments
....: non-octal character in escape sequence: "

It's seeing \1 as a possible octal sequence but when I'm trying to compile this regular expression it isn't working. I've tried backticks, single quotes, etc. I can't find in the docs where it says what to do with this, and it's kind of weird because this is how regular expressions work in most languages (yes, I know that doesn't mean it'll work in all of them.)

Don Branson
  • 13,631
  • 10
  • 59
  • 101
terryp
  • 219
  • 1
  • 3
  • 6

0 Answers0