Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Unix Match. Part 2 RegExp solution in Clear category for Unix Match. Part 2 by ridias
import assert from "assert";
function unixMatch(filename: string, pattern: string): boolean {
pattern = pattern.replace(/\./g, "\\.").replace(/\[\!/g, "[^")
return new RegExp(pattern).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!");
July 29, 2020