#!/usr/bin/gawk -fBEGIN{print"syntax: regexp"}/^\s*[^#]/{# Canonicalizes to a rooted pattern./\//||sub(/^/,"**/")gsub(/\./,"\\.")gsub(/\?/,"[^/]")gsub(/\*/,"[^/]*")gsub(/\[\^\/\]\*\[\^\/\]\*/,".*")# recovery for '**'sub(/^/,"^")/\/$/ || sub(/$/, "$")sub(/^\^\.\*\/\[\^\/\]\*/,"")||sub(/^\^\.\*\//,"(^|/)")}{print}
#!/usr/bin/perl -pBEGIN{print"syntax: regexp\n"}if(m,^\s*[^#],) {# Canonicalizes to a rooted pattern.m,/, or s,^,**/,;s,[\\\.\+],\\$&,g;s,\?,[^/],g;s,\*,[^/]*,g;s,\[\^/]\*\[\^/]\*/,(.*/)?,g;# recovery for '**/'# Turns to a whole-line pattern.s,^,^,;m,/$,ors,$,\$,;# Simplifies to an unrooted pattern if possible.s,^\^\(\.\*/\)\?,(^|/),;s,^\(\^\|/\)\[\^/]\*,,;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.