D2055.mawk-regex.sh (2192B)
1 #!/usr/bin/env bash 2 3 test-mawk-version() { 4 local v=$1 5 local r=$(echo yes | ~/opt/mawk/"$v"/bin/mawk '/^('\''[^'\'']*'\''|\$'\''([^\\'\'']|\\.)*'\''|\$?"([^\\"]|\\.)*"|\\.|[^[:space:]"'\''`;&|()])*/') 6 echo "$v: ${r:-no}" 7 } 8 9 test-mawk-version 1.3.3-20080909 10 test-mawk-version 1.3.3-20090705 11 test-mawk-version 1.3.3-20090710 12 test-mawk-version 1.3.3-20090721 13 test-mawk-version 1.3.4-20100419 14 test-mawk-version 1.3.4-20101210 15 test-mawk-version 1.3.4-20230404 16 17 function test-regex-matching { 18 local mawk=$1 19 echo "===============================================================================" 20 echo "mawk-path = $mawk" 21 echo 22 23 # echo yes | "$mawk" '/'\''[^'\'']*'\''|\$'\''([^\\'\'']|\\.)*'\''|\$?"([^\\"]|\\.)*"|\\.|[^[:space:]"'\''`;&|()]/' 24 # echo yes | "$mawk" '/\$'\''([^\\'\'']|\\.)*'\''|\$?"([^\\"]|\\.)*"|\\.|[^[:space:]"'\''`;&|()]/' 25 # echo yes | "$mawk" '/\$?"([^\\"]|\\.)*"|\\.|[^[:space:]"'\''`;&|()]/' 26 # echo yes | "$mawk" '/\\.|[^[:space:]"'\''`;&|()]/' 27 # echo yes | "$mawk" '/[^[:space:]"'\''`;&|()]/' 28 # echo yes | "$mawk" '/[^[:space:]()]/' 29 echo yes | "$mawk" '{if (/[[:space:]()]/) print "no"; else print "yes";}' # 文法エラー 30 echo '(' | "$mawk" '{if (/[()[:space:]]/) print "yes"; else print "no";}' # 駄目 31 echo '(' | "$mawk" '{if (/[()]/) print "yes"; else print "no";}' # OK 32 echo ' ' | "$mawk" '{if (/[[:space:]]/) print "yes"; else print "no";}' # 駄目 33 echo ' ' | "$mawk" '{if (/[ ]/) print "yes"; else print "no";}' # OK 34 echo 'a b c' | "$mawk" '{gsub(/[[:space:]]/, ""); print "[" $0 "] expect:[abc]";}' # 駄目 35 echo 'a b c' | "$mawk" '{gsub(/[^[:space:]]/, ""); print "[" $0 "] expect:[ ]";}' # 駄目 36 echo 'a b c' | "$mawk" '{gsub(/[[:alpha:]]/, ""); print "[" $0 "] expect:[ ]";}' # 駄目 37 echo 'a b c' | "$mawk" '{gsub(/[^[:alpha:]]/, ""); print "[" $0 "] expect:[abc]";}' # 駄目 38 echo 'a b c' | "$mawk" '{gsub(/[[=a=]]/, ""); print "[" $0 "] expect:[ b c]";}' # 駄目 39 } 40 41 #test-regex-matching ~/opt/mawk/1.3.3-20080909/bin/mawk 42 test-regex-matching ~/opt/mawk/1.3.3-20090705/bin/mawk 43 test-regex-matching ~/opt/mawk/1.3.3-20090710/bin/mawk