Skip to content

Instantly share code, notes, and snippets.

View Serabass's full-sized avatar
💭
I got nothing to do

Serabass Serabass

💭
I got nothing to do
  • Kazakhstan
View GitHub Profile
@donmccurdy
donmccurdy / wildcard-to-regexp.js
Last active February 21, 2024 06:49
Wildcard and glob matching in JavaScript.
/**
* Creates a RegExp from the given string, converting asterisks to .* expressions,
* and escaping all other characters.
*/
function wildcardToRegExp (s) {
return new RegExp('^' + s.split(/\*+/).map(regExpEscape).join('.*') + '$');
}
/**
* RegExp-escapes all characters in the given string.