Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Convert pattern so that regexp can be used solution in Clear category for Unix Match. Part 2 by Sim0000
import assert from "assert";
function unixMatch(filename: string, pattern: string): boolean {
const pat = pattern.replace(/\./g, '\\.').replace(/\?/g, '.').replace(/\*/g, '.*').replace(/\[!/g, '[^');
return RegExp(pat).test(filename);
}
console.log('Example:');
console.log(unixMatch('log1.txt', 'log[1234567890].txt'));
// These "asserts" are used for self-checking
assert.equal(unixMatch('log1.txt', 'log[1234567890].txt'), true);
assert.equal(unixMatch('log1.txt', 'log[!1].txt'), false);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Aug. 25, 2020
Comments: