Last Updated: 2021-05-16
I wanted to match files ending in
.js but not ones ending in
e.g to match
users.js but not
My first draft using a negative lookahead revealed a misunderstanding about lookaheads:
When called on
users.spec.js it returned
spec.js - i.e. the
spec despite the negative lookahead asking not to include that bit.
Essentially the issue was that the negative lookahead applied only after the
To understand more:
null(i.e this works for all our purposes )
Another, probably easier way to get it to work, is to rewrite with a negative lookbehind:
Watch out for prior greediness crowding out negative lookahead. Consider replacing problematic parts with negative look-behinds.