mbasso / natural-regex

Create regex from natural language
MIT License
152 stars 10 forks source link

Is there a way to express negation #2

Open haikyuu opened 6 years ago

haikyuu commented 6 years ago

General Information

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

mbasso commented 6 years ago

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