Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 21, 2021
1 parent 360b12f commit 45fbd39
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/regex-quantifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const pico = require('..');

/**
* See: https://github.com/gulpjs/glob-parent/issues/39#issuecomment-794075641
*/

const files = [
'data/100-123a_files/0/',
'data/100-123a_files/1/',
'data/100-123a_files/2/',
'data/100-123a_files/3/',
'data/100-123b_files/0/',
'data/100-123b_files/1/',
'data/100-123b_files/2/',
'data/100-123b_files/3/',
'data/100-123a_files/4/',
'data/100-123ax_files/0/',
'data/100-123A_files/0/',
'data/100-123A_files/1/',
'data/100-123A_files/2/',
'data/100-123A_files/3/',
'data/100-123B_files/0/',
'data/100-123B_files/1/',
'data/100-123B_files/2/',
'data/100-123B_files/3/',
'data/100-123A_files/4/',
'data/100-123AX_files/0/'
];

// ? is a wildcard for matching one character
// by escaping \\{0,3}, and then using `{ unescape: true }, we tell
// picomatch to treat those characters as a regex quantifier, versus
// a brace pattern.

const isMatch = pico('data/100-123?\\{0,3}_files/{0..3}/', { unescape: true });
console.log(files.filter(name => isMatch(name)));

// Alternatively, we can use a regex character class to be more specific
// In the following example, we'll only match uppercase alpha characters
const isMatch2 = pico('data/100-123[A-Z]*_files/{0..3}/', { unescape: true });
console.log(files.filter(name => isMatch2(name)));

0 comments on commit 45fbd39

Please sign in to comment.