natural-regex
natural-regex copied to clipboard
Is there a way to express negation
trafficstars
General Information
- [ ] Bug
- [x] Improvement
- [ ] Feature
- [ ] Other
Description Is there a way to express negation --> not end with js or similar? (Add images if possible)
Steps to reproduce
(Add link to a demo on https://jsfiddle.net or similar if possible)
Versions
- natural-regex:
- Browser:
Hi @haikyuu, at the moment this syntax is not supported. I'm not sure if we can implement negation as a general operator with regular expressions, I have to study if it is feasible. A regex that match that could be this one:
const regex = NaturalRegex.from(`
start not followed by
group
anything, ends with js
end group.
anything, end.
`);
// regex = /^(?!(?:.*js$)).*$/
regex.test('file.js'); // false
regex.test('file.json'); // true