JSFiddle - React, Tailwind, and code Playground
by Sahin Deniz
JavaScript
let expression = `
z-dn.net
z-dn.net*
*z-dn.net
*z-dn.net*
*.z-dn.net
.z-dn.net*
*.z-dn.net*
z-dn.net/*
*z-dn.net/*
*.z-dn.net/*
google.com/*/test
`;
expression = `
*.z-dn.net
`;
expression = expression
.replace(/^[. ]+|[^\w*]+$/gm, "")
.replace(/(?:\*+)?\.+(\*)+|([*])+/g, "$1$2")
.replace(
/(?:(?<!\[.*)\])|(?:[.*+?^${}()/[|\\](?![^[]*\]))/g,
"\\$&",
)
.replace(/(\\\*)+/g, ".*")
console.log(expression);
let expressions = expression.split("\n").map(_expression => {
if (!_expression) return;
return new RegExp(`^${_expression}(?:$|/.*$)$`, "gim");
});
expressions = expressions.filter(Boolean);
console.log(expressions);
let content = `
z-dn.net
z-dn.net.tr
z-dn.net/files
tr.z-dn.net
tr.z-dn.net/files
trz-dn.net/files
hi-static.z-dn.net/files/d31/da439d4059f3719e9264bc3af5197b31.jpg?a=1
hi-static.z-dn.net/items/d31/da439d4059f3719e9264bc3af5197b31.jpg?a=1
bit.ly/office2016txt
bit.ly/latexonbrainly`;
expressions.forEach(regexp => {
console.warn(regexp);
console.table(content.match(regexp));
});