2

I've come across a number of places on the interwebs showing that if you want to negate an entire regex pattern you can just embed it inside: (?! pattern here )

But instead it catches on nothing for me. I've tried it on a number of sites and apps that use regex, but no dice. Here's an example.

Suppose I have these strings:

strangecowfeet

mycow

yourcow

hiddendonkey

cowfishyummy

This pattern matches all except hiddendonkey:

cow

But then If I do:

(?!cow)

It doesn't match on anything. I've tried a bunch of variants I've seen around (trailing .* and .+ and spaces and anchors, etc), but to no avail.

Looks like I've overlooking a very basic flaw.

Community
  • 1
  • 1
micahhoover
  • 1,922
  • 6
  • 29
  • 52

0 Answers0