Last active
April 1, 2020 12:39
-
-
Save s-leroux/f6fd8b432f56579f7ad08f964c9f69ff to your computer and use it in GitHub Desktop.
Regex pattern tester. Related to https://twitter.com/freebsdfrau/status/1245253969447809024?s=20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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