natural-regex icon indicating copy to clipboard operation
natural-regex copied to clipboard

Is there a way to express negation

Open haikyuu opened this issue 7 years ago • 1 comments
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:

haikyuu avatar Sep 18 '18 09:09 haikyuu

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

mbasso avatar Sep 19 '18 20:09 mbasso