regex-combine-and
Combines multiple regexes into a single regex using lookaheads emulating AND
behaviour
Highlights
-
Written in Typescript
-
Matches multiline strings
-
Matches only if all match phrases exists in test string irrepective of order
Usage
Combines multiple regexes into a single regex using lookaheads
Obviously, you can use the | (pipe?) to represent OR, but there is no AND operator in regex. But we can emulate an AND behaviour by using lookaheads.
This lets you match paragraphs of text that contain ALL of a certain phrase, but in no particular order
const regexCombineAnd = ; combinedRegex = ; // /^(?=[\s\S]*a)/(?=[\s\S]*quick)(?=[\s\S]*brown)[\s\S]*$/m combinedRegex; // true combinedRegex; // true combinedRegex; // false combinedRegex; //true combinedRegex; // true
License
MIT © Nivrith