Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JS glob to regex

// Rudimentary code for matching globs with ? and *
// Escape the dots, change * to .* and ? to . 
// and make it match entire string
new RegExp
(
  '^' +
  rx.replaceAll('.', '.')
  .replaceAll('*', '.*')
  .replaceAll('?', '.') +
  '$'
)
 
PREVIOUS NEXT
Tagged: #JS #glob #regex
ADD COMMENT
Topic
Name
7+4 =