elapqpxsijws
elapqpxsijws

Reputation: 3

How to match files end not with regex

I am trying to filter all files not ending with, for instance mp3 or wv.
I have tried to use something like this ^.*(?<![mp3|wv])$ but this expression doesn't work.
Please help to create valid expression.

Upvotes: 0

Views: 62

Answers (2)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

Since a lookbehind is a zero-width assertion, you can write:

^.*(?<!mp3)(?<!wv)$

or better ($ is a zero-width assertion too):

^.*$(?<!mp3)(?<!wv)

if your regex flavor allows it (PCRE, Java), you can use an alternation:

^.*$(?<!mp3|wv)

Note: if your goal is only to know if a string doesn't end with "vw" or "mp3", you can test if (?:mp3|wv)$ is false.

Upvotes: 3

hwnd
hwnd

Reputation: 70732

You can use Negative Lookahead instead.

^(?!.*(?:mp3|wv)$).*

Upvotes: 3

Related Questions