0

I need a regex (javascript) that will process all files except for two. The file names look like this-

Epic_IKDH_Appt_Phone_Reminders_20191030.txt
Epic_NAMMI_Appt_Phone_Reminders_20191031.txt
QCNIL-Recall_Phone_Reminders_20191029.txt
Epic_SNA_Appt_No_Show_Reminders_20191029.txt

I want to process all files that don't start with QCNIL and Epic_SNA.

Tried this regex but it doesn't seem to work

^((?!QCNIL).)*$|^((?!Epic_SNA).)*$  

One of the other seems to work but not together.

Then tried this:

^((?!Epic_SNA)(?!QCNIL).)*$

This seems to work but with my limited knowledge of regular expressions, I'm afraid I might be missing something. Basically, if new file names are generated, I want them to also process. I only don't want to process the SNA and QCNIL files.

Toto
  • 89,455
  • 62
  • 89
  • 125
rut
  • 73
  • 5

2 Answers2

0

You need to perform the or inside the exclusion. Otherwise you are saying "it is not this" or "it is not that". You need to say it is not "this or that".

Also, did you intend the whole expression to be repeated by *, or only the .? Try the following, though there are more brackets than necessary:

^(?!((Epic_SNA)|(QCNIL))).*$
Gem Taylor
  • 5,381
  • 1
  • 9
  • 27
0

The second pattern ^((?!Epic_SNA)(?!QCNIL).)*$ would work but the approach taken is a tempered greedy token which will do 2 assertions before matching a single char and can be a costly operation in the number of steps.

You might simplify the pattern to use a negative lookahead at the start asserting what is directly to the right is not QCNIL or Epic_SNA.

Then match any char except a newline 1+ times to prevent matching an empty string.

^(?!QCNIL|Epic_SNA).+$

Regex demo

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