1

How do I find any string that starts with abc and doesn't have the word test anywhere in the rest of the string?

abc blah test (no match)
abc blah blah test (no match)
abc blah (match)

I found the following but I don't know how to put in the abc part.

^(?!.*Test).*$

Credit: https://stackoverflow.com/a/1318314/139698

Rod
  • 14,529
  • 31
  • 118
  • 230

1 Answers1

1

You can make the match case insensitive using for example an inline modifier (?i) and use word boundaries \b around test and after abc to prevent partial matches.

Match abc first, and use the assertion afterwards.

(?i)^abc\b(?!.*\bTest\b).*$

.Net regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70