I have written a regex to pick files of the format
(ABC.*\.DAT)
in perl.
How to write a negation for the above regex?
I already tried expressions like (?!ABC.*)\.DAT
or (?!(ABC.*\.DAT))
Any help is appreciated.
I have written a regex to pick files of the format
(ABC.*\.DAT)
in perl.
How to write a negation for the above regex?
I already tried expressions like (?!ABC.*)\.DAT
or (?!(ABC.*\.DAT))
Any help is appreciated.
(?s:(?!ABC).)*\.DAT
You can try this negation based regex. See demo.
The above can be safely embedded into a larger pattern. For example,
/^(?:(?!ABC).)*\.DAT\z/s
If you are trying to match the whole input, and if ABC
doesn't end with .
, .D
, .DA
or .DAT
, then the following will be faster:
/^(?!.*ABC)\.DAT\z/s