0

I'm trying to stub a rest operation and I need a pattern to match a string and then any character after that unless its a "/".

eg. /getAccounts5424675

I need to match this but the numbers can be anything however it must not match if there is a "/" after the get accounts part. There are other operations such as /getAccounts5424675/products4344 that cannot match.

I don't see a not character in Java such as ^ other than in character classes like [^abc] however I don't believe I can use that combined with a string to match.

  • `/getAccounts5424675/products4344` should not match at all or only the `/getAccounts5424675` should be matched there? Maybe `^/getAccounts[^/]+$` or `^/getAccounts[^/]+` if not – user3783243 Feb 16 '21 at 15:13
  • You can match something, and then use the negated character class you have mentioned, `[^/]*`. Something like `somestring[^/]*`. If you need to make sure there are no `/` till end of string, just append `$`, *the end of string anchor*. – Wiktor Stribiżew Feb 16 '21 at 15:15

0 Answers0