Skip to content

Instantly share code, notes, and snippets.

@kat0h
Created April 20, 2025 14:52
Show Gist options
  • Save kat0h/d6543eccd9370071c59013555d2ee1d9 to your computer and use it in GitHub Desktop.
Save kat0h/d6543eccd9370071c59013555d2ee1d9 to your computer and use it in GitHub Desktop.
Regex
const match=(h=>s=>r=>t=>(a=>a(a)(t))(f=>p=>r[0]=="^"?h(h)(s)(r.slice(1))(p):h(h)(s)(r)(p)?1:p.slice(1).length>0?f(f)(p.slice(1)):0))(h=>s=>r=>t=>r.length==0?1:r[1]=="*"?s(h)(s)(r[0])(r.slice(2))(t):r[0]=="$"&&r.length==1?t.length==0:t.length!=0&&(r[0]=="."||r[0]==t[0])?h(h)(s)(r.slice(1))(t.slice(1)):0)(h=>s=>c=>r=>t=>((a)=>a(a)(t))(f=>p=>h(h)(s)(r)(p)?1:p.length!=0&&(p[0]==c||c==".")?f(f)(p.slice(1)):0));
console.log(match("H...o")("Hello"));
console.log(match("a")("b"));
console.log(match("U.C")("UEC"));
console.log(match("U.C")("aEC"));
console.log(match("UU*EC")("UUUUEC"));
console.log(match("UU*C")("UEC"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment