I am tying to run the following regular expression on a string in Go
\(([0-9]+),([0-9.]+),(?:$([0-9]+))\)
but I keep getting the error unknown escape sequence: (
the string that I'm running it on is (1,53.38,$45) (2,88.62,$98) (3,78.48,$3) (4,72.30,$76) (5,30.18,$9) (6,46.34,$48)
So my question is, how do you escape parentheses in Go's regexp?
You need to escape the backslashes, because \(
isn't a valid excape sequence.
"\\(([0-9]+),([0-9.]+),(?:$([0-9]+))\\)"
More commonly you would use backticks for string literals without escaping:
`\(([0-9]+),([0-9.]+),(?:$([0-9]+))\)`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With