Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
unixMatch_part_1 solution in Clear category for Unix Match. Part 1 by Jon_Red
import assert from'assert'
function unixMatch(filename:string,pattern:string):boolean{
return Boolean(filename.match(
pattern.replace(/\./g,'\\.').replace(/\*/g,'.*').replace(/\?/g,'.')
))
}
// self-checks
assert.equal(unixMatch('somefile.txt','*'),true)
assert.equal(unixMatch('other.exe','*'),true)
assert.equal(unixMatch('my.exe','*.txt'),false)
assert.equal(unixMatch('log1.txt','log?.txt'),true)
assert.equal(unixMatch('log12.txt','log?.txt'),false)
assert.equal(unixMatch('log12.txt','log??.txt'),true)
Aug. 24, 2020
Comments: