否定Golang正则表达式中的整个字符串

I want to write a regex where I want to negate entire string.

I tried - inventory/[^getData](assumming it will check getData string not to be present in expression)

I want "inventory/getData" to fail above regex match whereas "inventory/get" to pass regex match. Basically want to negate string "getData" How can I do this?

If the entire string is inventory/getData or inventory/get then this will work as a positive match for inventory/get but not inventory/getData

^inventory/get$

^ matches the start of the string and $ matches the end

This pattern asserts that the string ends with get, if it ends with getData it will not match


To examine the more complex case of matching a negation, here are some example strings to be matched

  • 1) inventory/get
  • 2) inventory/getData
  • 3) inventory/snorkle
  • 4) inventory/getReal

inventory/[^g][^e][^t][^D][^a][^t][^a] matches 3 only. This is because the [^g][^e][^t] section is a non match for the other examples

inventory/(?:[^g][^e][^t][^D][^a][^t][^a]|get.*) matches all except for 2 -- not sure but perhaps this is what you are asking for? As you can see the negation is tailored to the test data