Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/awk -f
- #
- # Test several regex patterns against printable ASCII characters
- # Related to https://twitter.com/freebsdfrau/status/1245253969447809024?s=20
- #
- # Original: https://gist.github.com/s-leroux/f6fd8b432f56579f7ad08f964c9f69ff
- #
- BEGIN {
- # input !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
- expect = "............x..xxxxxxxxxx.......xxxxxxxxxxxxxxxxxxxxxxxxxx"
- # input (cont.) [\]^_`abcdefghijklmnopqrstuvwxyz{|}~
- expect = expect "....x.xxxxxxxxxxxxxxxxxxxxxxxxxx...."
- width = 12
- green = 32
- red = 31
- test["[-_[:alnum:]]"]
- test["[-[:alnum:]_]"]
- test["[_[:alnum:]-]"]
- test["[[:alnum:]_-]"]
- test["[a-zA-Z0-9_-]"]
- test["[-_a-zA-Z0-9]"]
- test["[-a-zA-Z0-9_]"]
- test["[_a-zA-Z0-9-]"]
- for (i = 33; i <= 126; i++) {
- input = input (c = sprintf("%c", i))
- for (re in test) m[re] = m[re] (match(c, re) ? "x" : ".")
- }
- printf "%-*s %s\n", width + 1, "input", input
- for (re in m) printf "%-*s \033[%sm%s\033[m\n", width, re,
- (m[re] == expect ? green : red), m[re]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement