Advanced globbing with Extglobs
masterExtglobs allow for more complex pattern matching based on occurrences of a pattern:
| Pattern | Description |
|---|---|
@(pattern) | Match only one consecutive occurrence of pattern |
*(pattern) | Match zero or more consecutive occurrences of pattern |
+(pattern) | Match one or more consecutive occurrences of pattern |
?(pattern) | Match zero or one consecutive occurrences of pattern |
!(pattern) | Match anything but pattern |
By default, risky quantified extglobs are treated literally. You can increase the nesting limit using the maxExtglobRecursion option.
const pm = require('picomatch');
// *(pattern) matches ZERO or more of "pattern"
console.log(pm.isMatch('a', 'a*(z)')); // true
console.log(pm.isMatch('az', 'a*(z)')); // true
console.log(pm.isMatch('azzz', 'a*(z)')); // true
// +(pattern) matches ONE or more of "pattern"
console.log(pm.isMatch('a', 'a+(z)')); // false
console.log(pm.isMatch('az', 'a+(z)')); // true
// supports multiple extglobs
console.log(pm.isMatch('foo.bar', '!(foo).!(bar)')); // false
// supports nested extglobs
console.log(pm.isMatch('foo.bar', '!(!(foo)).!(!(bar))')); // true
// increase the limit to allow a small amount of nested quantified extglobs
console.log(pm.isMatch('aaa', '+(+(a))', { maxExtglobRecursion: 1 })); // true