用ahk正则方式判断中文字集

  1. /*
  2. ahk正则判断双字节正则为[^\x00-\xff],判断汉字字集范围表达方式为:[\x{范围}-\x{范围}]。例如判断是否是基本汉字[\x{4E00}-\x{9FA5}]+
  3. */
  4. str:="字集顚亾?礱龑龖瘇龘〇㠩略?戔㵸"
  5. result:={},chars:=""
  6. GetStrLen(str,Array)
  7. for key,value In Array
  8. {
  9. if Type:=CheckChineseCharset(value){
  10. if !result[Type]{
  11. result[Type]:=value "、"
  12. }Else{
  13. result[Type].=value "、"
  14. }
  15. }
  16. }
  17. for key,value In result
  18. {
  19. if key
  20. chars.=key ":{ " Trim(value,"、") " }`n"
  21. }
  22. MsgBox % chars
  23. ; 中文字集判断
  24. ; GBK汉字范围->8140-FEFE
  25. ; GB2312汉字范围->B0A1-F7FE
  26. CheckChineseCharset(String){
  27. VarSetCapacity(str,StrPut(String, "CP936")*4),StrPut(String,&str, "CP936")
  28. L1:=Format("0x{:X}",NumGet(&str,0,"UChar")),L2:=Format("0x{:X}",NumGet(&str,1,"UChar"))
  29. if String~="^[\x{4E00}-\x{9FFF}]$"{
  30. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  31. Return "GB2312"
  32. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  33. Return "GBK"
  34. }Else
  35. Return "非中文"
  36. }Else if String~="^[\x{3400}-\x{4DBF}]$"{ ; 扩展A
  37. Return "扩A"
  38. }Else if String~="^[\x{20000}-\x{2A6DF}]$"{ ; 扩展B
  39. Return "扩B"
  40. }Else if String~="^[\x{2A700}-\x{2B73F}]$"{ ; 扩展C
  41. Return "扩C"
  42. }Else if String~="^[\x{2B740}-\x{2B81F}]$"{ ; 扩展D
  43. Return "扩D"
  44. }Else if String~="^[\x{2B820}-\x{2CEAF}]$"{ ; 扩展E
  45. Return "扩E"
  46. }Else if String~="^[\x{2CEB0}-\x{2EBEF}]$"{ ; 扩展F
  47. Return "扩F"
  48. }Else if String~="^[\x{30000}-\x{3134F}]$"{ ; 扩展G
  49. Return "扩G"
  50. }Else if String~="^[\x{31350}-\x{323BC}]$"{ ; 扩展H
  51. Return "扩H"
  52. }Else if String~="^[\x{3007}]$"{ ;
  53. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  54. Return "GB2312"
  55. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  56. Return "GBK"
  57. }Else
  58. Return "〇"
  59. }Else if String~="^[\x{2F00}-\x{2FD5}]$"{
  60. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  61. Return "GB2312"
  62. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  63. Return "GBK"
  64. }Else
  65. Return "康熙部首"
  66. }Else if String~="^[\x{2E80}-\x{2EF3}]$"{
  67. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  68. Return "GB2312"
  69. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  70. Return "GBK"
  71. }Else
  72. Return "部首扩展"
  73. }Else if String~="^[\x{F900}-\x{FAD9}]$"{
  74. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  75. Return "GB2312"
  76. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  77. Return "GBK"
  78. }Else
  79. Return "CJK兼容汉字"
  80. }Else if String~="^[\x{2F800}-\x{2FA1D}]$"{
  81. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  82. Return "GB2312"
  83. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  84. Return "GBK"
  85. }Else
  86. Return "CJK兼容扩展"
  87. }Else if String~="^[\x{E815}-\x{E86F}]$"{
  88. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  89. Return "GB2312"
  90. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  91. Return "GBK"
  92. }Else
  93. Return "PUA(GBK)部件"
  94. }Else if String~="^[\x{E400}-\x{E5E8}]$"{
  95. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  96. Return "GB2312"
  97. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  98. Return "GBK"
  99. }Else
  100. Return "部件扩展"
  101. Return "部件扩展"
  102. }Else if String~="^[\x{E600}-\x{E6CF}]$"{
  103. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  104. Return "GB2312"
  105. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  106. Return "GBK"
  107. }Else
  108. Return "PUA增补"
  109. }Else if chars~="^[\x{31C0}-\x{31E3}]$"{
  110. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  111. Return "GB2312"
  112. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  113. Return "GBK"
  114. }Else
  115. Return "汉字笔画"
  116. }Else if String~="^[\x{2FF0}-\x{2FFB}]$"{
  117. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  118. Return "GB2312"
  119. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  120. Return "GBK"
  121. }Else
  122. Return "汉字结构"
  123. }Else if String~="^[\x{3105}-\x{312F}]$"{
  124. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  125. Return "GB2312"
  126. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  127. Return "GBK"
  128. }Else
  129. Return "汉语注音"
  130. }Else if String~="^[\x{31A0}-\x{31BA}]$"{
  131. if (L1>=0xB0&&L2>=0xA1&&L1<=0xF7&&L2<=0xFE){
  132. Return "GB2312"
  133. }Else if (L1>=0x81&&L2>=0x40&&L1<=0xFE&&L2<=0xFE){
  134. Return "GBK"
  135. }Else
  136. Return "注音扩展"
  137. }Else if String~="^[\x00-\xff]$"{
  138. Return "未知分类"
  139. }
  140. }
  141. GetStrLen(str,ByRef obj:="") {
  142. Static Count:=0
  143. str:=RegExReplace(str,"[\s\t\r\n]")
  144. obj:=StrSplit(RTrim(RegExReplace(str,"(.)","$1☯☯☯",Count),"☯☯☯"),"☯☯☯")
  145. Return Count
  146. }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
其他函数教程

【函数】调出文件夹选择对话框

2021-11-24 8:59:23

教程

学习AHK的第一天

2021-12-1 14:14:28

2 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
  1. hexuren
    1河许人给您打赏了¥2
  2. 蜜獾哥

    影子开启ZB模式

个人中心
购物车
优惠劵
私信列表
搜索