4

I want to search the files having "write" but at the same time I don't want my search results to include "writeful". So if there is

  • write
  • writeful
  • writer
  • fwrite
  • foowrite
  • Write

I want everything but writeful. Basically I need something with or without regex to exclude writeful.

I know one not-so-good-way to do it is search for writeful. And then do next search and exclude the files from previous search results. However it will fail if write and writeful both are present in same file.

2
  • 1
    Have you tried the regex search write(?!ful)?
    – Phil W
    Commented Nov 15, 2022 at 10:22
  • write(?!(ful|Ful|FUL)) This can be used for providing multiple exclusion words and these all are case sensitive. Thanks @PhilW it worked. You can provide it as answer and I'll be happy to accept it
    – love gupta
    Commented Nov 15, 2022 at 11:06

1 Answer 1

3

You can use negative lookahead in regex to exclude matches. Case sensitivity can be handled as part of regex control flags, though this may be outside the expression itself depending on the tool.

A simple example of allowing regular expression matches for "write" as long as it isn't followed by "ful" is:

write(?!ful)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .