Reputation: 441
I'm trying to match all files except those ending with .bmp.
Due to some constraints I can't use negation (?:, !:) and references (\1, ...).
I've made an expression and it works for most of the strings:
^\w+\.([^b].*|b|b[^m].*|bm|bm[^p].*|bmp.+)$
It matches everything that doesn't end with .bmp - including test.txt, test.bmp.txt, etc. But unfourtanely, it does allow test.bi.bmp.
Any idea on how to improve the regex so it would just match files not ending with .bmp?
Upvotes: 5
Views: 422
Reputation: 79185
why not:
^.*[^p]$|^.*[^m]p$|^.*[^b]mp$|^.*[^.]bmp$
?
An alternative is ^.*([^p]|[^m]p|[^b]mp|[^.]bmp)$
(shorter).
Upvotes: 5
Reputation: 11
/^.+\.([^b][^.]*|b|b[^m][^.]*|bm|bm[^p][^.]*|bmp[^.]+)$/
just make sure that the dot before 'bmp' is the last dot
Upvotes: 1
Reputation: 4442
Not too elegant but works:
^.*([^b][^m][^p]|b[^m][^p]|[^b]m[^p]|[^b][^m]p|bm[^p]|[^b]mp)$
Upvotes: 0