Regular Expressions 101

golang re2 negative lookahead

Open Workspace
  • Golang
  • Unit Tests
2

Regular Expression

`
^((.{0,4})|(/api[^/].*)|(/ap[^i].*)|(/a[^p].*)|(/[^a].*))$
`
gm

Description

Aquivalent solution for golang's unsupported negative lookahead in re2 flavor of go's regex. This example provides a negative lookahead similar to (?!/api/) ignoring routes with the /api/ prefix at the start.

Submitted by misha