-1

I am able to use negative lookahead in Javascript to not match certain IPs like 127.0.0.1 but I am unable to use the same for my microservice that runs in Go.

This is the regex I use in Javascript -

^(?!127\.0\.0\.1)(([1-9])|([1-9][0-9])|([1][0-9][0-9])|(2[0-1][0-9])|(22[0-3]))\.(((([0-9])|([1-9][0-9])|([1][0-9][0-9])|(2[0-4][0-9])|(25[0-5]))\.){2})(([1-9])|([1-9][0-9])|([1][0-9][0-9])|(2[0-4][0-9])|(25[0-5]))$

1 Answers1

1

Negative lookahead is not support in Go's regular expressions. See the question, Negative look-ahead in Go regular expressions

Might want to look at using the package cidranger instead.

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135