Skip to content

Instantly share code, notes, and snippets.

@s-leroux
Last active April 1, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-leroux/f6fd8b432f56579f7ad08f964c9f69ff to your computer and use it in GitHub Desktop.
Save s-leroux/f6fd8b432f56579f7ad08f964c9f69ff to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Test several regex patterns against the characters in the ASCII printable range
# Related to https://twitter.com/freebsdfrau/status/1245253969447809024?s=20
#
seq 33 126 | awk '
BEGIN {
split("[-_[:alpha:]] [-[:alpha:]_] [_[:alpha:]-] [[:alpha:]_-]", tests, "[[:blank:]]+")
}
{
char = sprintf("%c", $1);
input = input char;
for (key in tests) {
results[tests[key]] = results[tests[key]] (match(char, tests[key]) ? "x" : ".");
}
}
END {
print "input ", input
for (key in results)
print key, results[key]
}
' | column -s:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment