由城西编写的
效果演示:
#SingleInstance Force #NoEnv SetWorkingDir %A_ScriptDir% SetBatchLines -1 Gui,Destroy Gui Font, s12 Gui Add, Edit, x3 y6 w288 h27 vinputextge Gui Font Gui Add, Button, x213 y70 w80 h37 g区间生成, 生成 Gui Add, Text, x4 y45 w191 h63, 区间格式:`n`n①[12,78] 表示 >=12,<=78`n②(12,78) 表示 >12,<78`n③[,15) 表示 >=0,小于15 Gui Show, w297 h113, 正整数区间正则生成 return GuiEscape: GuiClose: ExitApp 区间生成: Gui,Submit,NoHide str3= inputextge:=RegExReplace(inputextge,"\s+") if !(inputextge~="^[\((\[](\d*)[,,](\d*)[\))\]]$") { MsgBox,输入有误,请重新输入! return } if (inputextge="") return inputextge1:=RegExReplace(inputextge,"[\((\[](\d*)[,,](\d*)[\))\]]","$1,$2") lnum:=RegExReplace(inputextge1,",.*$") hnum:=RegExReplace(inputextge1,".*?,") lnum:= lnum ? lnum : 0 hnum:= hnum ? hnum : "无穷" if (hnum<>"无穷") { if (lnum>=hnum) { MsgBox,输入有误,请重新输入! return } } znumqj:=(inputextge~="\[") ? "闭" : "开" ynumqj:=(inputextge~="\]") ? "闭" : "开" lnumlen:=StrLen(lnum) hnumlen:=StrLen(hnum) if (lnumlen=hnumlen) and (hnum<>"无穷") { xc= loop,% lnumlen { xa:=SubStr(lnum,1,A_Index) xb:=SubStr(hnum,1,A_Index) if (xa=xb) xc:=xa else break } lnum1:=RegExReplace(lnum,"^" xc) hnum1:=RegExReplace(hnum,"^" xc) outs1:=大于小数(lnum1,hnum1) outs2:=小于大数(lnum1,hnum1) outs1:=RegExReplace(outs1,"\|?\[\d\-\d\]\\d\{\d+\}$") xxg1:=SubStr(lnum1,1,1) xxg2:=SubStr(hnum1,1,1) if (outs2~=xxg2 "\[0") { if (xxg1<>xxg2-1) { outs2:=RegExReplace(outs2,"^.+?(?=" xxg2 "\[0)") lns1:=xc "[" xxg1+1 "-" xxg2-1 "]\d{" StrLen(hnum1)-1 "}" outs2:=lns1 "|" xc . outs2 } else outs2:=xc . RegExReplace(outs2,"^.+?(?=" xxg2 "\[0)") } else outs2:="" if (outs1="") { if (xxg1=xxg2-1) str3:="" else str3:=xc . "[" xxg1+1 "-" xxg2-1 "]" } else str3:=xc . outs1 "|" outs2 } else { outs1:=大于小数(lnum,hnum) outs2:=小于大数(lnum,hnum) str3:=outs1 "|" outs2 } if (znumqj="闭") str3:=lnum "|" str3 if (ynumqj="闭") { if (hnum<>"无穷") str3:=str3 "|" hnum } str3:=RegExReplace(str3,"\\d\{0\}") str3:=RegExReplace(str3,"\{1\}") str3:=RegExReplace(str3,"\[1\-0\]","1") str3:=RegExReplace(str3,"\[(\d)\-\1\]","$1") str3:=RegExReplace(str3,"\{(\d+),\1\}","{$1}") str3:=RegExReplace(str3,"^\||\|$") str3:=RegExReplace(str3,"\|{2,}","|") str3=^(%str3%)$ Clipboard:=str3 MsgBox,% "代码已生成到剪切板!`n"str3 return 大于小数(lnum:=0,hnum:="无穷") { lnumlen:=StrLen(lnum) loop,%lnumlen%{ a1:=SubStr(lnum,1,lnumlen-A_Index) a2:=SubStr(lnum,lnumlen-A_Index+1,1) a3:="\d{" A_Index-1 "}" if (a2+1>9) continue str:=a1 . "[" a2+1 . "-9]" . a3 str0.=str0 ? "|" str : str } return str0 } 小于大数(lnum:=0,hnum:="无穷") { lnumlen:=StrLen(lnum) hnumlen:=StrLen(hnum) if (hnum="无穷") { str2:="[1-9]\d{" . lnumlen ",}" } else { if (hnumlen > lnumlen+1) str1:="[1-9]\d{" . lnumlen . "," hnumlen-2 . "}" loop,% hnumlen { a1:=SubStr(hnum,1,A_Index-1) a2:=SubStr(hnum,A_Index,1) if (A_Index=1) { if (a2-1<1) continue } else { if (a2-1<0) continue } if (a1="") str:=a1 . "[1-" . a2-1 . "]" . "\d{" . hnumlen-A_Index . "}" else str:=a1 . "[0-" . a2-1 . "]" . "\d{" . hnumlen-A_Index . "}" str2.=str2 ? "|" str : str } } str3:="" str3:=str1 ? str1 : "" str3.=str2 ? "|" str2 : "" return RegExReplace(str3,"^\|") }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)