{"id":680,"date":"2009-10-17T23:14:00","date_gmt":"2009-10-17T03:14:00","guid":{"rendered":""},"modified":"2013-11-17T12:47:19","modified_gmt":"2013-11-17T04:47:19","slug":"c%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e6%80%bb%e7%bb%93%e7%bd%97%e5%88%97","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/680.html","title":{"rendered":"C#\u6b63\u5219\u8868\u8fbe\u5f0f\u603b\u7ed3\u7f57\u5217"},"content":{"rendered":"<p>\u53ea\u80fd\u8f93\u5165\u6570\u5b57\uff1a&#8221;^[0-9]*$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165n\u4f4d\u7684\u6570\u5b57\uff1a&#8221;^\\d{n}$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u81f3\u5c11n\u4f4d\u7684\u6570\u5b57\uff1a&#8221;^\\d{n,}$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165m~n\u4f4d\u7684\u6570\u5b57\uff1a\u3002&#8221;^\\d{m,n}$&#8221;<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u96f6\u548c\u975e\u96f6\u5f00\u5934\u7684\u6570\u5b57\uff1a&#8221;^(0|[1-9][0-9]*)$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u6709\u4e24\u4f4d\u5c0f\u6570\u7684\u6b63\u5b9e\u6570\uff1a&#8221;^[0-9] (.[0-9]{2})?$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u67091~3\u4f4d\u5c0f\u6570\u7684\u6b63\u5b9e\u6570\uff1a&#8221;^[0-9] (.[0-9]{1,3})?$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u975e\u96f6\u7684\u6b63\u6574\u6570\uff1a&#8221;^\\ ?[1-9][0-9]*$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u975e\u96f6\u7684\u8d1f\u6574\u6570\uff1a&#8221;^\\-[1-9][]0-9&#8243;*$\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u957f\u5ea6\u4e3a3\u7684\u5b57\u7b26\uff1a&#8221;^.{3}$&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u753126\u4e2a\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff1a&#8221;^[A-Za-z] $&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u753126\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff1a&#8221;^[A-Z] $&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u753126\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff1a&#8221;^[a-z] $&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u7531\u6570\u5b57\u548c26\u4e2a\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff1a&#8221;^[A-Za-z0-9] $&#8221;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u7531\u6570\u5b57\u300126\u4e2a\u82f1\u6587\u5b57\u6bcd\u6216\u8005\u4e0b\u5212\u7ebf\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff1a&#8221;^\\w $&#8221;\u3002<\/p>\n<p>\u9a8c\u8bc1\u7528\u6237\u5bc6\u7801\uff1a&#8221;^[a-zA-Z]\\w{5,17}$&#8221;\u6b63\u786e\u683c\u5f0f\u4e3a\uff1a\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u957f\u5ea6\u57286~18\u4e4b\u95f4\uff0c\u53ea\u80fd\u5305\u542b\u5b57\u7b26\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002<\/p>\n<p>\u9a8c\u8bc1\u662f\u5426\u542b\u6709^%&amp;\u2019,;=?$\\&#8221;\u7b49\u5b57\u7b26\uff1a&#8221;[^%&amp;\u2019,;=?$\\x22] &#8220;\u3002<\/p>\n<p>\u53ea\u80fd\u8f93\u5165\u6c49\u5b57\uff1a&#8221;^[\\u4e00-\\u9fa5]{0,}$&#8221;<\/p>\n<p>\u9a8c\u8bc1Email\u5730\u5740\uff1a&#8221;^\\w ([- .]\\w )*@\\w ([-.]\\w )*\\.\\w ([-.]\\w )*$&#8221;\u3002<\/p>\n<p>\u9a8c\u8bc1InternetURL\uff1a&#8221;^http:\/\/([\\w-] \\.) [\\w-] (\/[\\w-.\/?%&amp;=]*)?$&#8221;\u3002<\/p>\n<p>\u9a8c\u8bc1\u7535\u8bdd\u53f7\u7801\uff1a&#8221;^(\\(\\d{3,4}-)|\\d{3.4}-)?\\d{7,8}$&#8221;\u6b63\u786e\u683c\u5f0f\u4e3a\uff1a&#8221;XXX-XXXXXXX&#8221;\u3001&#8221;XXXX-XXXXXXXX&#8221;\u3001&#8221;XXX-XXXXXXX&#8221;\u3001&#8221;XXX-XXXXXXXX&#8221;\u3001&#8221;XXXXXXX&#8221;\u548c&#8221;XXXXXXXX&#8221;\u3002<\/p>\n<p>\u9a8c\u8bc1\u8eab\u4efd\u8bc1\u53f7\uff0815\u4f4d\u621618\u4f4d\u6570\u5b57\uff09\uff1a&#8221;^\\d{15}|\\d{18}$&#8221;\u3002<\/p>\n<p>\u9a8c\u8bc1\u4e00\u5e74\u768412\u4e2a\u6708\uff1a&#8221;^(0?[1-9]|1[0-2])$&#8221;\u6b63\u786e\u683c\u5f0f\u4e3a\uff1a&#8221;01&#8243;\uff5e&#8221;09&#8243;\u548c&#8221;1&#8243;\uff5e&#8221;12&#8243;\u3002<\/p>\n<p>\u9a8c\u8bc1\u4e00\u4e2a\u6708\u768431\u5929\uff1a&#8221;^((0?[1-9])|((1|2)[0-9])|30|31)$&#8221;\u6b63\u786e\u683c\u5f0f\u4e3a\uff1b&#8221;01&#8243;\uff5e&#8221;09&#8243;\u548c&#8221;1&#8243;\uff5e&#8221;31&#8243;\u3002<\/p>\n<p>\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5236\u7f51\u9875\u8868\u5355\u91cc\u7684\u6587\u672c\u6846\u8f93\u5165\u5185\u5bb9\uff1a<\/p>\n<p>\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5236\u53ea\u80fd\u8f93\u5165\u4e2d\u6587\uff1aonkeyup=&#8221;value=value.replace(\/[^\\u4E00-\\u9FA5]\/g,\u2019\u2019)&#8221; onbeforepaste=&#8221;clipboardData.setData(\u2019text\u2019,clipboardData.getData(\u2019text\u2019).replace(\/[^\\u4E00-\\u9FA5]\/g,\u2019\u2019))&#8221;<\/p>\n<p>\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5236\u53ea\u80fd\u8f93\u5165\u5168\u89d2\u5b57\u7b26\uff1a onkeyup=&#8221;value=value.replace(\/[^\\uFF00-\\uFFFF]\/g,\u2019\u2019)&#8221; onbeforepaste=&#8221;clipboardData.setData(\u2019text\u2019,clipboardData.getData(\u2019text\u2019).replace(\/[^\\uFF00-\\uFFFF]\/g,\u2019\u2019))&#8221;<\/p>\n<p>\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5236\u53ea\u80fd\u8f93\u5165\u6570\u5b57\uff1aonkeyup=&#8221;value=value.replace(\/[^\\d]\/g,\u2019\u2019) &#8220;onbeforepaste=&#8221;clipboardData.setData(\u2019text\u2019,clipboardData.getData(\u2019text\u2019).replace(\/[^\\d]\/g,\u2019\u2019))&#8221;<\/p>\n<p>\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5236\u53ea\u80fd\u8f93\u5165\u6570\u5b57\u548c\u82f1\u6587\uff1aonkeyup=&#8221;value=value.replace(\/[\\W]\/g,\u2019\u2019) &#8220;onbeforepaste=&#8221;clipboardData.setData(\u2019text\u2019,clipboardData.getData(\u2019text\u2019).replace(\/[^\\d]\/g,\u2019\u2019))&#8221;<\/p>\n<p>\u5f97\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4eceURL\u5730\u5740\u4e2d\u63d0\u53d6\u6587\u4ef6\u540d\u7684javascript\u7a0b\u5e8f\uff0c\u5982\u4e0b\u7ed3\u679c\u4e3apage1<\/p>\n<p>s=&#8221;http:\/\/www.9499.net\/page1.htm&#8221;<\/p>\n<p>s=s.replace(\/(.*\\\/){0,}([^\\.] ).*\/ig,&#8221;$2&#8243;)<\/p>\n<p>alert(s)<\/p>\n<p>\u5339\u914d\u53cc\u5b57\u8282\u5b57\u7b26(\u5305\u62ec\u6c49\u5b57\u5728\u5185)\uff1a[^\\x00-\\xff]<\/p>\n<p>\u5e94\u7528\uff1a\u8ba1\u7b97\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff08\u4e00\u4e2a\u53cc\u5b57\u8282\u5b57\u7b26\u957f\u5ea6\u8ba12\uff0cASCII\u5b57\u7b26\u8ba11\uff09<\/p>\n<p>String.prototype.len=function(){return this.replace([^\\x00-\\xff]\/g,&#8221;aa&#8221;).length;}<\/p>\n<p>\u5339\u914d\u7a7a\u884c\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\\n[\\s| ]*\\r<\/p>\n<p>\u5339\u914dHTML\u6807\u8bb0\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\/&lt;(.*)&gt;.*&lt;\\\/\\1&gt;|&lt;(.*) \\\/&gt;\/<\/p>\n<p>\u5339\u914d\u9996\u5c3e\u7a7a\u683c\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a(^\\s*)|(\\s*$)<\/p>\n<p>String.prototype.trim = function()<\/p>\n<p>{<\/p>\n<p>return this.replace(\/(^\\s*)|(\\s*$)\/g, &#8220;&#8221;);<\/p>\n<p>}<\/p>\n<p>\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u89e3\u548c\u8f6c\u6362IP\u5730\u5740\uff1a<\/p>\n<p>\u4e0b\u9762\u662f\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914dIP\u5730\u5740\uff0c\u5e76\u5c06IP\u5730\u5740\u8f6c\u6362\u6210\u5bf9\u5e94\u6570\u503c\u7684Javascript\u7a0b\u5e8f\uff1a<\/p>\n<p>function IP2V(ip)<\/p>\n<p>{<\/p>\n<p>re=\/(\\d )\\.(\\d )\\.(\\d )\\.(\\d )\/g \/\/\u5339\u914dIP\u5730\u5740\u7684\u6b63\u5219\u8868\u8fbe\u5f0f<\/p>\n<p>if(re.test(ip))<\/p>\n<p>{<\/p>\n<p>return RegExp.$1*Math.pow(255,3)) RegExp.$2*Math.pow(255,2)) RegExp.$3*255 RegExp.$4*1<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>throw new Error(&#8220;Not a valid IP address!&#8221;)<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u4e0d\u8fc7\u4e0a\u9762\u7684\u7a0b\u5e8f\u5982\u679c\u4e0d\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u800c\u76f4\u63a5\u7528split\u51fd\u6570\u6765\u5206\u89e3\u53ef\u80fd\u66f4\u7b80\u5355\uff0c\u7a0b\u5e8f\u5982\u4e0b\uff1a<\/p>\n<p>var ip=&#8221;10.100.20.168&#8243;<\/p>\n<p>ip=ip.split(&#8220;.&#8221;)<\/p>\n<p>alert(&#8220;IP\u503c\u662f\uff1a&#8221; (ip[0]*255*255*255 ip[1]*255*255 ip[2]*255 ip[3]*1))<\/p>\n<p>\u7b26\u53f7\u89e3\u91ca\uff1a<\/p>\n<p>\u5b57\u7b26<\/p>\n<p>\u63cf\u8ff0<\/p>\n<p>\\<\/p>\n<p>\u5c06\u4e0b\u4e00\u4e2a\u5b57\u7b26\u6807\u8bb0\u4e3a\u4e00\u4e2a\u7279\u6b8a\u5b57\u7b26\u3001\u6216\u4e00\u4e2a\u539f\u4e49\u5b57\u7b26\u3001\u6216\u4e00\u4e2a \u5411\u540e\u5f15\u7528\u3001\u6216\u4e00\u4e2a\u516b\u8fdb\u5236\u8f6c\u4e49\u7b26\u3002\u4f8b\u5982\uff0c\u2019n\u2019 \u5339\u914d\u5b57\u7b26 &#8220;n&#8221;\u3002\u2019\\n\u2019 \u5339\u914d\u4e00\u4e2a\u6362\u884c\u7b26\u3002\u5e8f\u5217 \u2019\\\\\u2019 \u5339\u914d &#8220;\\&#8221; \u800c &#8220;\\(&#8221; \u5219\u5339\u914d &#8220;(&#8220;\u3002<\/p>\n<p>^<\/p>\n<p>\u5339\u914d\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002\u5982\u679c\u8bbe\u7f6e\u4e86 RegExp \u5bf9\u8c61\u7684 Multiline \u5c5e\u6027\uff0c^ \u4e5f\u5339\u914d \u2019\\n\u2019 \u6216 \u2019\\r\u2019 \u4e4b\u540e\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>$<\/p>\n<p>\u5339\u914d\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002\u5982\u679c\u8bbe\u7f6e\u4e86RegExp \u5bf9\u8c61\u7684 Multiline \u5c5e\u6027\uff0c$ \u4e5f\u5339\u914d \u2019\\n\u2019 \u6216 \u2019\\r\u2019 \u4e4b\u524d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>*<\/p>\n<p>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u96f6\u6b21\u6216\u591a\u6b21\u3002\u4f8b\u5982\uff0czo* \u80fd\u5339\u914d &#8220;z&#8221; \u4ee5\u53ca &#8220;zoo&#8221;\u3002* \u7b49\u4ef7\u4e8e{0,}\u3002<\/p>\n<p>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u4e00\u6b21\u6216\u591a\u6b21\u3002\u4f8b\u5982\uff0c\u2019zo \u2019 \u80fd\u5339\u914d &#8220;zo&#8221; \u4ee5\u53ca &#8220;zoo&#8221;\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;z&#8221;\u3002 \u7b49\u4ef7\u4e8e {1,}\u3002<\/p>\n<p>?<\/p>\n<p>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u96f6\u6b21\u6216\u4e00\u6b21\u3002\u4f8b\u5982\uff0c&#8221;do(es)?&#8221; \u53ef\u4ee5\u5339\u914d &#8220;do&#8221; \u6216 &#8220;does&#8221; \u4e2d\u7684&#8221;do&#8221; \u3002? \u7b49\u4ef7\u4e8e {0,1}\u3002<\/p>\n<p>{n}<\/p>\n<p>n \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u5339\u914d\u786e\u5b9a\u7684 n \u6b21\u3002\u4f8b\u5982\uff0c\u2019o{2}\u2019 \u4e0d\u80fd\u5339\u914d &#8220;Bob&#8221; \u4e2d\u7684 \u2019o\u2019\uff0c\u4f46\u662f\u80fd\u5339\u914d &#8220;food&#8221; \u4e2d\u7684\u4e24\u4e2a o\u3002<\/p>\n<p>{n,}<\/p>\n<p>n \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u81f3\u5c11\u5339\u914dn \u6b21\u3002\u4f8b\u5982\uff0c\u2019o{2,}\u2019 \u4e0d\u80fd\u5339\u914d &#8220;Bob&#8221; \u4e2d\u7684 \u2019o\u2019\uff0c\u4f46\u80fd\u5339\u914d &#8220;foooood&#8221; \u4e2d\u7684\u6240\u6709 o\u3002\u2019o{1,}\u2019 \u7b49\u4ef7\u4e8e \u2019o \u2019\u3002\u2019o{0,}\u2019 \u5219\u7b49\u4ef7\u4e8e \u2019o*\u2019\u3002<\/p>\n<p>{n,m}<\/p>\n<p>m \u548c n \u5747\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u5176\u4e2dn &lt;= m\u3002\u6700\u5c11\u5339\u914d n \u6b21\u4e14\u6700\u591a\u5339\u914d m \u6b21\u3002\u4f8b\u5982\uff0c&#8221;o{1,3}&#8221; \u5c06\u5339\u914d &#8220;fooooood&#8221; \u4e2d\u7684\u524d\u4e09\u4e2a o\u3002\u2019o{0,1}\u2019 \u7b49\u4ef7\u4e8e \u2019o?\u2019\u3002\u8bf7\u6ce8\u610f\u5728\u9017\u53f7\u548c\u4e24\u4e2a\u6570\u4e4b\u95f4\u4e0d\u80fd\u6709\u7a7a\u683c\u3002<\/p>\n<p>?<\/p>\n<p>\u5f53\u8be5\u5b57\u7b26\u7d27\u8ddf\u5728\u4efb\u4f55\u4e00\u4e2a\u5176\u4ed6\u9650\u5236\u7b26 (*, , ?, {n}, {n,}, {n,m}) \u540e\u9762\u65f6\uff0c\u5339\u914d\u6a21\u5f0f\u662f\u975e\u8d2a\u5a6a\u7684\u3002\u975e\u8d2a\u5a6a\u6a21\u5f0f\u5c3d\u53ef\u80fd\u5c11\u7684\u5339\u914d\u6240\u641c\u7d22\u7684\u5b57\u7b26\u4e32\uff0c\u800c\u9ed8\u8ba4\u7684\u8d2a\u5a6a\u6a21\u5f0f\u5219\u5c3d\u53ef\u80fd\u591a\u7684\u5339\u914d\u6240\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32 &#8220;oooo&#8221;\uff0c\u2019o ?\u2019 \u5c06\u5339\u914d\u5355\u4e2a &#8220;o&#8221;\uff0c\u800c \u2019o \u2019 \u5c06\u5339\u914d\u6240\u6709 \u2019o\u2019\u3002<\/p>\n<p>.<\/p>\n<p>\u5339\u914d\u9664 &#8220;\\n&#8221; \u4e4b\u5916\u7684\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002\u8981\u5339\u914d\u5305\u62ec \u2019\\n\u2019 \u5728\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff0c\u8bf7\u4f7f\u7528\u8c61 \u2019[.\\n]\u2019 \u7684\u6a21\u5f0f\u3002<\/p>\n<p>(pattern)<\/p>\n<p>\u5339\u914d pattern \u5e76\u83b7\u53d6\u8fd9\u4e00\u5339\u914d\u3002\u6240\u83b7\u53d6\u7684\u5339\u914d\u53ef\u4ee5\u4ece\u4ea7\u751f\u7684 Matches \u96c6\u5408\u5f97\u5230\uff0c\u5728VBScript \u4e2d\u4f7f\u7528 SubMatches \u96c6\u5408\uff0c\u5728JScript \u4e2d\u5219\u4f7f\u7528 $0\u2026$9 \u5c5e\u6027\u3002\u8981\u5339\u914d\u5706\u62ec\u53f7\u5b57\u7b26\uff0c\u8bf7\u4f7f\u7528 \u2019\\(\u2019 \u6216 \u2019\\)\u2019\u3002<\/p>\n<p>(?:pattern)<\/p>\n<p>\u5339\u914d pattern \u4f46\u4e0d\u83b7\u53d6\u5339\u914d\u7ed3\u679c\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u662f\u4e00\u4e2a\u975e\u83b7\u53d6\u5339\u914d\uff0c\u4e0d\u8fdb\u884c\u5b58\u50a8\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u8fd9\u5728\u4f7f\u7528 &#8220;\u6216&#8221; \u5b57\u7b26 (|) \u6765\u7ec4\u5408\u4e00\u4e2a\u6a21\u5f0f\u7684\u5404\u4e2a\u90e8\u5206\u662f\u5f88\u6709\u7528\u3002\u4f8b\u5982\uff0c \u2019industr(?:y|ies) \u5c31\u662f\u4e00\u4e2a\u6bd4 \u2019industry|industries\u2019 \u66f4\u7b80\u7565\u7684\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>(?=pattern)<\/p>\n<p>\u6b63\u5411\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u5339\u914d pattern \u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u83b7\u53d6\u5339\u914d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u5339\u914d\u4e0d\u9700\u8981\u83b7\u53d6\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u4f8b\u5982\uff0c\u2019Windows (?=95|98|NT|2000)\u2019 \u80fd\u5339\u914d &#8220;Windows 2000&#8221; \u4e2d\u7684 &#8220;Windows&#8221; \uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;Windows 3.1&#8221; \u4e2d\u7684 &#8220;Windows&#8221;\u3002\u9884\u67e5\u4e0d\u6d88\u8017\u5b57\u7b26\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u4e00\u4e2a\u5339\u914d\u53d1\u751f\u540e\uff0c\u5728\u6700\u540e\u4e00\u6b21\u5339\u914d\u4e4b\u540e\u7acb\u5373\u5f00\u59cb\u4e0b\u4e00\u6b21\u5339\u914d\u7684\u641c\u7d22\uff0c\u800c\u4e0d\u662f\u4ece\u5305\u542b\u9884\u67e5\u7684\u5b57\u7b26\u4e4b\u540e\u5f00\u59cb\u3002<\/p>\n<p>(?!pattern)<\/p>\n<p>\u8d1f\u5411\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u4e0d\u5339\u914d pattern \u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u83b7\u53d6\u5339\u914d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u5339\u914d\u4e0d\u9700\u8981\u83b7\u53d6\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u4f8b\u5982\u2019Windows (?!95|98|NT|2000)\u2019 \u80fd\u5339\u914d &#8220;Windows 3.1&#8221; \u4e2d\u7684 &#8220;Windows&#8221;\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;Windows 2000&#8221; \u4e2d\u7684 &#8220;Windows&#8221;\u3002\u9884\u67e5\u4e0d\u6d88\u8017\u5b57\u7b26\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u4e00\u4e2a\u5339\u914d\u53d1\u751f\u540e\uff0c\u5728\u6700\u540e\u4e00\u6b21\u5339\u914d\u4e4b\u540e\u7acb\u5373\u5f00\u59cb\u4e0b\u4e00\u6b21\u5339\u914d\u7684\u641c\u7d22\uff0c\u800c\u4e0d\u662f\u4ece\u5305\u542b\u9884\u67e5\u7684\u5b57\u7b26\u4e4b\u540e\u5f00\u59cb<\/p>\n<p>x|y<\/p>\n<p>\u5339\u914d x \u6216 y\u3002\u4f8b\u5982\uff0c\u2019z|food\u2019 \u80fd\u5339\u914d &#8220;z&#8221; \u6216 &#8220;food&#8221;\u3002\u2019(z|f)ood\u2019 \u5219\u5339\u914d &#8220;zood&#8221; \u6216 &#8220;food&#8221;\u3002<\/p>\n<p>[xyz]<\/p>\n<p>\u5b57\u7b26\u96c6\u5408\u3002\u5339\u914d\u6240\u5305\u542b\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982\uff0c \u2019[abc]\u2019 \u53ef\u4ee5\u5339\u914d &#8220;plain&#8221; \u4e2d\u7684 \u2019a\u2019\u3002<\/p>\n<p>[^xyz]<\/p>\n<p>\u8d1f\u503c\u5b57\u7b26\u96c6\u5408\u3002\u5339\u914d\u672a\u5305\u542b\u7684\u4efb\u610f\u5b57\u7b26\u3002\u4f8b\u5982\uff0c \u2019[^abc]\u2019 \u53ef\u4ee5\u5339\u914d &#8220;plain&#8221; \u4e2d\u7684\u2019p\u2019\u3002<\/p>\n<p>[a-z]<\/p>\n<p>\u5b57\u7b26\u8303\u56f4\u3002\u5339\u914d\u6307\u5b9a\u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u2019[a-z]\u2019 \u53ef\u4ee5\u5339\u914d \u2019a\u2019 \u5230 \u2019z\u2019 \u8303\u56f4\u5185\u7684\u4efb\u610f\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u3002<\/p>\n<p>[^a-z]<\/p>\n<p>\u8d1f\u503c\u5b57\u7b26\u8303\u56f4\u3002\u5339\u914d\u4efb\u4f55\u4e0d\u5728\u6307\u5b9a\u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u2019[^a-z]\u2019 \u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u4e0d\u5728 \u2019a\u2019 \u5230 \u2019z\u2019 \u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<p>\\b<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u5355\u8bcd\u8fb9\u754c\uff0c\u4e5f\u5c31\u662f\u6307\u5355\u8bcd\u548c\u7a7a\u683c\u95f4\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c \u2019er\\b\u2019 \u53ef\u4ee5\u5339\u914d&#8221;never&#8221; \u4e2d\u7684 \u2019er\u2019\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;verb&#8221; \u4e2d\u7684 \u2019er\u2019\u3002<\/p>\n<p>\\B<\/p>\n<p>\u5339\u914d\u975e\u5355\u8bcd\u8fb9\u754c\u3002\u2019er\\B\u2019 \u80fd\u5339\u914d &#8220;verb&#8221; \u4e2d\u7684 \u2019er\u2019\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;never&#8221; \u4e2d\u7684 \u2019er\u2019\u3002<\/p>\n<p>\\cx<\/p>\n<p>\u5339\u914d\u7531 x \u6307\u660e\u7684\u63a7\u5236\u5b57\u7b26\u3002\u4f8b\u5982\uff0c \\cM \u5339\u914d\u4e00\u4e2a Control-M \u6216\u56de\u8f66\u7b26\u3002x \u7684\u503c\u5fc5\u987b\u4e3a A-Z \u6216 a-z \u4e4b\u4e00\u3002\u5426\u5219\uff0c\u5c06 c \u89c6\u4e3a\u4e00\u4e2a\u539f\u4e49\u7684 \u2019c\u2019 \u5b57\u7b26\u3002<\/p>\n<p>\\d<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u3002\u7b49\u4ef7\u4e8e [0-9]\u3002<\/p>\n<p>\\D<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\u3002\u7b49\u4ef7\u4e8e [^0-9]\u3002<\/p>\n<p>\\f<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u6362\u9875\u7b26\u3002\u7b49\u4ef7\u4e8e \\x0c \u548c \\cL\u3002<\/p>\n<p>\\n<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u6362\u884c\u7b26\u3002\u7b49\u4ef7\u4e8e \\x0a \u548c \\cJ\u3002<\/p>\n<p>\\r<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u56de\u8f66\u7b26\u3002\u7b49\u4ef7\u4e8e \\x0d \u548c \\cM\u3002<\/p>\n<p>\\s<\/p>\n<p>\u5339\u914d\u4efb\u4f55\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u9875\u7b26\u7b49\u7b49\u3002\u7b49\u4ef7\u4e8e [ \\f\\n\\r\\t\\v]\u3002<\/p>\n<p>\\S<\/p>\n<p>\u5339\u914d\u4efb\u4f55\u975e\u7a7a\u767d\u5b57\u7b26\u3002\u7b49\u4ef7\u4e8e [^ \\f\\n\\r\\t\\v]\u3002<\/p>\n<p>\\t<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u5236\u8868\u7b26\u3002\u7b49\u4ef7\u4e8e \\x09 \u548c \\cI\u3002<\/p>\n<p>\\v<\/p>\n<p>\u5339\u914d\u4e00\u4e2a\u5782\u76f4\u5236\u8868\u7b26\u3002\u7b49\u4ef7\u4e8e \\x0b \u548c \\cK\u3002<\/p>\n<p>\\w<\/p>\n<p>\u5339\u914d\u5305\u62ec\u4e0b\u5212\u7ebf\u7684\u4efb\u4f55\u5355\u8bcd\u5b57\u7b26\u3002\u7b49\u4ef7\u4e8e\u2019[A-Za-z0-9_]\u2019\u3002<\/p>\n<p>\\W<\/p>\n<p>\u5339\u914d\u4efb\u4f55\u975e\u5355\u8bcd\u5b57\u7b26\u3002\u7b49\u4ef7\u4e8e \u2019[^A-Za-z0-9_]\u2019\u3002<\/p>\n<p>\\xn<\/p>\n<p>\u5339\u914d n\uff0c\u5176\u4e2d n \u4e3a\u5341\u516d\u8fdb\u5236\u8f6c\u4e49\u503c\u3002\u5341\u516d\u8fdb\u5236\u8f6c\u4e49\u503c\u5fc5\u987b\u4e3a\u786e\u5b9a\u7684\u4e24\u4e2a\u6570\u5b57\u957f\u3002\u4f8b\u5982\uff0c\u2019\\x41\u2019 \u5339\u914d &#8220;A&#8221;\u3002\u2019\\x041\u2019 \u5219\u7b49\u4ef7\u4e8e \u2019\\x04\u2019 &amp; &#8220;1&#8221;\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u53ef\u4ee5\u4f7f\u7528 ASCII \u7f16\u7801\u3002.<\/p>\n<p>\\num<\/p>\n<p>\u5339\u914d num\uff0c\u5176\u4e2d num \u662f\u4e00\u4e2a\u6b63\u6574\u6570\u3002\u5bf9\u6240\u83b7\u53d6\u7684\u5339\u914d\u7684\u5f15\u7528\u3002\u4f8b\u5982\uff0c\u2019(.)\\1\u2019 \u5339\u914d\u4e24\u4e2a\u8fde\u7eed\u7684\u76f8\u540c\u5b57\u7b26\u3002<\/p>\n<p>\\n<\/p>\n<p>\u6807\u8bc6\u4e00\u4e2a\u516b\u8fdb\u5236\u8f6c\u4e49\u503c\u6216\u4e00\u4e2a\u5411\u540e\u5f15\u7528\u3002\u5982\u679c \\n \u4e4b\u524d\u81f3\u5c11 n \u4e2a\u83b7\u53d6\u7684\u5b50\u8868\u8fbe\u5f0f\uff0c\u5219 n \u4e3a\u5411\u540e\u5f15\u7528\u3002\u5426\u5219\uff0c\u5982\u679c n \u4e3a\u516b\u8fdb\u5236\u6570\u5b57 (0-7)\uff0c\u5219 n \u4e3a\u4e00\u4e2a\u516b\u8fdb\u5236\u8f6c\u4e49\u503c\u3002<\/p>\n<p>\\nm<\/p>\n<p>\u6807\u8bc6\u4e00\u4e2a\u516b\u8fdb\u5236\u8f6c\u4e49\u503c\u6216\u4e00\u4e2a\u5411\u540e\u5f15\u7528\u3002\u5982\u679c \\nm \u4e4b\u524d\u81f3\u5c11\u6709 nm \u4e2a\u83b7\u5f97\u5b50\u8868\u8fbe\u5f0f\uff0c\u5219 nm \u4e3a\u5411\u540e\u5f15\u7528\u3002\u5982\u679c \\nm \u4e4b\u524d\u81f3\u5c11\u6709 n \u4e2a\u83b7\u53d6\uff0c\u5219 n \u4e3a\u4e00\u4e2a\u540e\u8ddf\u6587\u5b57 m \u7684\u5411\u540e\u5f15\u7528\u3002\u5982\u679c\u524d\u9762\u7684\u6761\u4ef6\u90fd\u4e0d\u6ee1\u8db3\uff0c\u82e5 n \u548c m \u5747\u4e3a\u516b\u8fdb\u5236\u6570\u5b57 (0-7)\uff0c\u5219 \\nm \u5c06\u5339\u914d\u516b\u8fdb\u5236\u8f6c\u4e49\u503c nm\u3002<\/p>\n<p>\\nml<\/p>\n<p>\u5982\u679c n \u4e3a\u516b\u8fdb\u5236\u6570\u5b57 (0-3)\uff0c\u4e14 m \u548c l \u5747\u4e3a\u516b\u8fdb\u5236\u6570\u5b57 (0-7)\uff0c\u5219\u5339\u914d\u516b\u8fdb\u5236\u8f6c\u4e49\u503c nml\u3002<\/p>\n<p>\\un<\/p>\n<p>\u5339\u914d n\uff0c\u5176\u4e2d n \u662f\u4e00\u4e2a\u7528\u56db\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u5b57\u8868\u793a\u7684 Unicode \u5b57\u7b26\u3002\u4f8b\u5982\uff0c \\u00A9 \u5339\u914d\u7248\u6743\u7b26\u53f7 (?)\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ea\u80fd\u8f93\u5165\u6570\u5b57\uff1a&#8221;^[0-9]*$&#8221;\u3002 \u53ea\u80fd\u8f93\u5165n\u4f4d\u7684\u6570\u5b57\uff1a&#8221;^\\d{n}$ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-680","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"predecessor-version":[{"id":4600,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/680\/revisions\/4600"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}