{"id":4356,"date":"2019-06-24T14:02:20","date_gmt":"2019-06-24T06:02:20","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4356"},"modified":"2019-06-24T14:06:31","modified_gmt":"2019-06-24T06:06:31","slug":"%e4%bb%8e%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4356","title":{"rendered":"\u4ece[]\u5f00\u59cb\u5b66\u4e60\u6b63\u5219\u8868\u8fbe\u5f0f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6b63\u5219\u8868\u8fbe\u5f0f\u975e\u5e38\u5bb9\u6613\u5fd8\u8bb0\uff0c\u800c\u4e14\u5b66\u7cbe\u901a\u975e\u5e38\u7684\u96be\u3002\u5e73\u65f6\u7528\u7684\u4e0d\u591a\uff0c\u6216\u8005\u7528\u5230\u7684\u90fd\u53ef\u4ee5\u5728\u7f51\u4e0a\u627e\u5230\u3002\u4f46\u662f\u4e00\u822c\u53ea\u6709\u53d1\u751f\u6027\u80fd\u95ee\u9898\u65f6\uff0c\u624d\u4f1a\u53bb\u4ece\u5934\u5b66\u4e60\u5b83\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c31\u6bd4\u5982\uff0c\u4e00\u4e2a&#8221;[]&#8221;\u5b57\u7b26\u7ec4(Character Classes)\u90fd\u80fd\u8ba9\u5f88\u591a\u4eba\u641e\u9519\u3002\u4eca\u5929\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u4ece\u96f6\uff0c\u4ece[]\u5f00\u59cb\u5b66\u4e60\u548c\u4e86\u89e3\u4e00\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\u5427\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g4c7535u9bj209r083mxr.jpg\" alt=\"\" \/><figcaption>\u4ece\u96f6\u5f00\u59cb\u5b66\u4e60\u6b63\u5219\u8868\u8fbe\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">[]\u80fd\u591f\u5339\u914d\u6240\u5305\u542b\u7684\u4e00\u7cfb\u5217\u5b57\u7b26\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c[]\u867d\u7136\u80fd\u5339\u914d\u5176\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f46\u5339\u914d\u7684\u7ed3\u679c\u53ea\u80fd\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u4e0d\u662f\u591a\u4e2a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982[abc]\u8868\u793a\u5b57\u7b26\u201ca\u201d\u6216\u201cb\u201d\u6216\u201cc\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[]\u652f\u6301\u7528\u8fde\u5b57\u7b26\u201c-\u201d\u8fde\u63a5\u4e24\u4e2a\u5b57\u7b26\uff0c\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u8303\u56f4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u201c-\u201d\u524d\u540e\u7684\u4e24\u4e2a\u5b57\u7b26\u662f\u6709\u987a\u5e8f\u7684\uff0c\u5373\u4f7f\u7528\u76f8\u540c\u7684\u7f16\u7801\u65f6\uff0c\u540e\u9762\u7684\u5b57\u7b26\u7801\u4f4d\u5e94\u5927\u4e8e\u6216\u7b49\u4e8e\u524d\u9762\u5b57\u7b26\u7684\u7801\u4f4d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982[a-z]\u8868\u793a\u4efb\u610f\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u3002\u800c\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528[z-a]\u5219\u4f1a\u62a5\u201c[x-y] \u8303\u56f4\u7684\u987a\u5e8f\u98a0\u5012\u201d\u8fd9\u6837\u7684\u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u90e8\u5206\u5728\u6b63\u5219\u4e2d\u6709\u7279\u6b8a\u610f\u4e49\u3001\u5728\u5339\u914d\u5176\u672c\u8eab\u65f6\u9700\u8f6c\u4e49\u7684\u5b57\u7b26\uff0c\u5728[]\u5185\u662f\u4e0d\u9700\u8981\u8f6c\u4e49\u7684\u3002\u5fc5\u987b\u8f6c\u4e49\u7684\u53ea\u6709\u201c\\\u201d\u3001\u201c[\u201d\u548c\u201c]\u201d\uff0c\u800c\u201c^\u201d\u51fa\u73b0\u5728[]\u5f00\u59cb\u4f4d\u7f6e\uff0c\u201c-\u201d\u524d\u540e\u6784\u6210\u8303\u56f4\u533a\u95f4\u65f6\uff0c\u9700\u8981\u8f6c\u4e49\uff0c\u51fa\u73b0\u5728\u5176\u5b83\u4f4d\u7f6e\u4e0d\u9700\u8981\u8f6c\u4e49\uff0c\u4f8b\u5982[\\^.$^{[(|)*+?-\\]\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e0d\u6784\u6210\u6b67\u4e49\u7684\u60c5\u51b5\u4e0b\uff0c\u201c[\u201d\u548c\u201c]\u201d\u53ef\u4ee5\u4e0d\u7528\u8f6c\u4e49\uff0c\u7a0b\u5e8f\u4e5f\u53ef\u4ee5\u5f97\u5230\u9884\u671f\u7ed3\u679c\uff0c\u4f46\u662f\u8fd9\u79cd\u5199\u6cd5\u53ef\u8bfb\u6027\u8f83\u5dee\uff0c\u800c\u4e14\u51fa\u73b0\u9519\u8bef\u65f6\u4e0d\u6613\u6392\u67e5\uff0c\u56e0\u6b64\u4e0d\u63a8\u8350\u8fd9\u79cd\u5199\u6cd5\u3002\u4f8b\u5982\u4e0b\u9762\u7684\u5199\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Regex reg = new Regex(\"[^]]+\");  \/\/\u4e0d\u63a8\u8350<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e38\u89c1\u9519\u8bef\u7528\u6cd5\uff1a\u56e0\u4e3a[]\u672c\u8eab\u8868\u793a\u7684\u5c31\u662f\u5b57\u7b26\u4e4b\u95f4\u201c\u6216\u201d\u7684\u5173\u7cfb\uff0c\u56e0\u6b64\u5728[]\u4e2d\u4f7f\u7528\u201c|\u201d\u6765\u8868\u793a\u201c\u6216\u201d\u7684\u5173\u7cfb\u662f\u9519\u8bef\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3e\u4f8b\uff1a[a|b|c]\u8868\u793a\u7684\u662f\u201ca\u201d\u6216\u201cb\u201d\u6216\u201cc\u201d\u6216\u201c|\u201d\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3e\u4f8b\uff1a\u6e90\u5b57\u7b26\u4e32\uff1aab|ac\uff1b\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a[a|b|c]+\uff1b\u5339\u914d\u7ed3\u679c\uff1aab|ac\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">[^ ] \u6392\u9664\u578b\u5b57\u7b26\u7ec4<\/h2>\n\n\n\n<ul class=\"wp-block-list\">null<li>[^ ]\u8868\u793a\u5339\u914d\u4efb\u610f\u4e00\u4e2a\u672a\u5217\u4e3e\u7684\u5b57\u7b26\uff0c\u540c\u6837\u7684\uff0c\u5339\u914d\u7684\u7ed3\u679c\u4e5f\u53ea\u80fd\u662f\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982[^abc]\u8868\u793a\u9664\u5b57\u7b26\u201ca\u201d\u3001\u201cb\u201d\u3001\u201cc\u201d\u5916\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/li><li> [^ ]\u4e5f\u652f\u6301\u5b57\u7b26\u5206\u7ec4\uff0c\u4f8b\u5982[^0-9]\u8868\u793a\u9664\u6570\u5b57\u5916\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u624b\u6700\u5bb9\u6613\u72af\u7684\u9519\u8bef\u5c31\u662f\uff0c\u7528[^abc]\u6216[^(abc)]\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u4e0d\u5305\u542b\u201cabc\u201d\u5b50\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\u4e0b\u9762\u8fd9\u4e9b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6e90\u5b57\u7b26\u4e32\uff1astring yourStr = &#8220;bbbccc&#8221;;<br>\u89c4\u5219\u63cf\u8ff0\uff1a\u53d6\u51fayourStr\u4e2d\u683c\u5f0f\u4e3a&lt;\u2026&gt;\uff0c\u4f46&lt;&gt;\u4e2d\u4e0d\u662fabc\u7684\u5185\u5bb9<br>\u9884\u671f\u7ed3\u679c\uff1a&lt;aaa&gt;\u3001&lt;ddd&gt;<br>\u9519\u8bef\u5199\u6cd5\uff1a&lt;[^abc]&gt;<em> \u6b63\u786e\u5199\u6cd5\uff1a<\/em>&lt;<em>(?!abc<\/em>&gt;<em>)[^<\/em>&gt;<em>]<\/em>&gt;<\/p><cite>https:\/\/www.xttblog.com<\/cite><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u4e00\u70b9\u5e76\u4e0d\u5e38\u89c1\uff0c\\b\u5728\u5b57\u7b26\u7ec4\u5916\u8868\u793a\u5355\u8bcd\u8fb9\u754c\uff0c\u4f46\u662f\u5728\u5b57\u7b26\u7ec4\u5185[\\b]\u8868\u793a\u9000\u683c\u7b26\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4356\">\u4ece[]\u5f00\u59cb\u5b66\u4e60\u6b63\u5219\u8868\u8fbe\u5f0f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u975e\u5e38\u5bb9\u6613\u5fd8\u8bb0\uff0c\u800c\u4e14\u5b66\u7cbe\u901a\u975e\u5e38\u7684\u96be\u3002\u5e73\u65f6\u7528\u7684\u4e0d\u591a\uff0c\u6216\u8005\u7528\u5230\u7684\u90fd\u53ef\u4ee5\u5728\u7f51\u4e0a\u627e\u5230\u3002\u4f46\u662f\u4e00\u822c\u53ea\u6709\u53d1\u751f\u6027\u80fd\u95ee\u9898 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1533,1979,1038,1978,1977],"class_list":["post-4356","post","type-post","status-publish","format-standard","hentry","category-java","tag-1533","tag-1979","tag-1038","tag-1978","tag-1977"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4356"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4356\/revisions"}],"predecessor-version":[{"id":4358,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4356\/revisions\/4358"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}