- 论坛徽章:
- 145
|
回复 4# 6954658
here you are
$ echo 2-122,139-555,777,888-1023,2-65533 | awk -F, 'function dg(c,n,r){for(n=1;n<=c;n++)r=r"[0-9]";return(r)}function re(x, c,d,t,r,cnt){t=split(x,a,"-");if(t==1)return(x"|");s=a[1];e=a[2];while(s<=e){if(s==e)return(r s"|");if(cnt++>15)return(r);t=10**c;sh=int(s/t/10);sh=sh?sh:"";ss=(int(s/t)%10);sn=(sh+1)*t*10;if(sn<=e){r=r sh "["ss"-9]"dg(c)"|";c++;s=sn;continue}if((e-s)/t<1){c--;continue};d=int((e-s)/t);r=r sh "["ss"-"ss+d-1"]" dg(c)"|";c--;s+=d*t}return(r"|")}{for(n=1;n<=NF;n++){p=p re($n)}for(n=1;n<=9;n++)gsub("\\["n"-"n"\\]",n,p);gsub("[|]$",")$",p);print "^("p}'
^([2-9]|[1-9][0-9]|1[0-1][0-9]|12[0-1]|122|139|1[4-9][0-9]|[2-4][0-9][0-9]|5[0-4][0-9]|55[0-4]|555|777|88[8-9]|89[0-9]|9[0-9][0-9]|10[0-1][0-9]|102[0-2]|1023|[2-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-2]|65533)$
$ echo 2-122,139-555,777,888-1023,2-65533 | awk -F, 'function dg(c,n,r){for(n=1;n<=c;n++)r=r"\\d";return(r)}function re(x, c,d,t,r,cnt){t=split(x,a,"-");if(t==1)return(x"|");s=a[1];e=a[2];while(s<=e){if(s==e)return(r s"|");if(cnt++>15)return(r);t=10**c;sh=int(s/t/10);sh=sh?sh:"";ss=(int(s/t)%10);sn=(sh+1)*t*10;if(sn<=e){r=r sh "["ss"-9]"dg(c)"|";c++;s=sn;continue}if((e-s)/t<1){c--;continue};d=int((e-s)/t);r=r sh "["ss"-"ss+d-1"]" dg(c)"|";c--;s+=d*t}return(r"|")}{for(n=1;n<=NF;n++){p=p re($n)}for(n=1;n<=9;n++)gsub("\\["n"-"n"\\]",n,p);gsub("[|]$",")$",p);print "^("p}'
^([2-9]|[1-9]\d|1[0-1]\d|12[0-1]|122|139|1[4-9]\d|[2-4]\d\d|5[0-4]\d|55[0-4]|555|777|88[8-9]|89\d|9\d\d|10[0-1]\d|102[0-2]|1023|[2-9]|[1-9]\d|[1-9]\d\d|[1-9]\d\d\d|[1-5]\d\d\d\d|6[0-4]\d\d\d|65[0-4]\d\d|655[0-2]\d|6553[0-2]|65533)$
|
|