mirror of
https://github.com/xuxiaobo-bobo/boda_jsEnv.git
synced 2025-04-23 04:04:25 +08:00
14 lines
446 B
JavaScript
14 lines
446 B
JavaScript
// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
|
|
|
|
function escapeRegExp(string) {
|
|
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
}
|
|
|
|
function match(wildcard, s) {
|
|
const regexString = escapeRegExp(wildcard).replace(/\\\*/g, '\\S*').replace(/\\\?/g, '.');
|
|
const regex = new RegExp(regexString);
|
|
return regex.test(s);
|
|
}
|
|
|
|
module.exports = {match};
|