{"id":4810,"date":"2020-03-11T08:44:22","date_gmt":"2020-03-11T00:44:22","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=4810"},"modified":"2020-03-11T09:17:20","modified_gmt":"2020-03-11T01:17:20","slug":"%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e6%8f%90%e5%8f%96%e5%9c%b0%e5%9d%80%e4%b8%ad%e7%9a%84%e7%9c%81%e3%80%81%e5%b8%82%e3%80%81%e5%8c%ba%e7%ad%89%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/4810.html","title":{"rendered":"\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u5730\u5740\u4e2d\u7684\u7701\u3001\u5e02\u3001\u533a\u7b49\u4fe1\u606f"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u6700\u8fd1\u5bf9\u8fd9\u4e00\u5757\u7684\u5185\u5bb9\u6bd4\u8f83\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u6536\u96c6\u6574\u7406\u4e86\u4e00\u4e9b\u8fd9\u65b9\u9762\u7684\u5185\u5bb9\uff0c\u65b9\u4fbf\u4ee5\u540e\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003\u548c\u4f7f\u7528\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<p>\u8fd9\u4e2a\u529f\u80fd\u8bf4\u767d\u4e86\u5176\u5b9e\u5c31\u662f\u5b57\u7b26\u4e32\u5904\u7406\uff0c\u4f46\u56e0\u4e3a\u56fd\u5185\u7684\u7701\u5e02\u533a\u5730\u5740\u53ef\u80fd\u6027\u975e\u5e38\u591a\uff0c\u6240\u4ee5\u4e0d\u65b9\u4fbf\u7528\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\u65b9\u6cd5\u8fdb\u884c\u5904\u7406\uff0c\u8fd9\u65f6\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff08\u53ea\u80fd\u4fdd\u8bc1\u63d0\u53d6\u7ed3\u679c\u7684\u5927\u6982\u51c6\u786e\uff0c\u56e0\u4e3a\u5b9e\u9645\u751f\u6d3b\u4e2d\u7684\u60c5\u51b5\u5404\u79cd\u5404\u6837\uff0c\u5f88\u96be\u5b8c\u5168\u5339\u914d\uff0c\u9664\u975e\u5728\u586b\u5199\u8f93\u5165\u7684\u65f6\u5019\u5c31\u8fdb\u884c\u4e25\u683c\u63a7\u5236\uff0c\u4f46\u8fd9\u5728\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u90fd\u662f\u4e0d\u73b0\u5b9e\u7684\uff09\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u5b9e\u73b0\u4fe1\u606f\u63d0\u53d6\u7684\u529f\u80fd\uff0c\u53e6\u4e00\u65b9\u9762\u4e5f\u662f\u60f3\u501f\u6b64\u987a\u4fbf\u719f\u6089\u4e00\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6355\u83b7\u7ec4\u7684\u4f7f\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u56e0\u4e3a\u7528\u5230\u7684\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6355\u83b7\u7ec4\u7684\u6982\u5ff5\uff0c\u5148\u7b80\u5355\u6574\u7406\u4e00\u4e0b\u6355\u83b7\u7ec4\u7684\u6982\u5ff5\u548c\u7528\u6cd5\uff1a<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u6355\u83b7\u7ec4\u5206\u4e3a\uff1a<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li>\u666e\u901a\u6355\u83b7\u7ec4(Expression)<\/li><li>\u547d\u540d\u6355\u83b7\u7ec4(?Expression)<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\u666e\u901a\u6355\u83b7\u7ec4\uff1a<\/h5>\n\n\n\n<p class=\"has-text-color has-vivid-red-color\">\u4ece\u6b63\u5219\u8868\u8fbe\u5f0f\u5de6\u4fa7\u5f00\u59cb\uff0c\u6bcf\u51fa\u73b0\u4e00\u4e2a\u5de6\u62ec\u53f7&#8221;(&#8220;\u8bb0\u505a\u4e00\u4e2a\u5206\u7ec4\uff0c\u5206\u7ec4\u7f16\u53f7\u4ece 1 \u5f00\u59cb\u30020 \u4ee3\u8868\u6574\u4e2a\u8868\u8fbe\u5f0f\u3002\u5373\uff0c<strong>(Expression)<\/strong>\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u547d\u540d\u6355\u83b7\u7ec4\uff1a<\/h5>\n\n\n\n<p class=\"has-text-color has-vivid-red-color\">\u6bcf\u4e2a\u4ee5\u5de6\u62ec\u53f7\u5f00\u59cb\u7684\u547d\u540d\u6355\u83b7\u7ec4<strong>(?Expression)<\/strong>\uff0c\u90fd\u7d27\u8ddf\u7740&nbsp;<strong>?<\/strong>\uff0c\u800c\u540e\u624d\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u975e\u6355\u83b7\u7ec4\uff1a<\/h5>\n\n\n\n<p class=\"has-text-color has-vivid-red-color\">\u5728\u5de6\u62ec\u53f7\u540e\u7d27\u8ddf&nbsp;<strong>?:<\/strong>\uff0c\u800c\u540e\u518d\u52a0\u4e0a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6784\u6210\u975e\u6355\u83b7\u7ec4&nbsp;<strong>(?:Expression)<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u7136\u540e\u518d\u6574\u7406\u4e00\u4e0b\u4e2d\u56fd\u5404\u7701\u7ea7\u57ce\u5e02\u5217\u8868\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>34\u4e2a\u7701\u7ea7\u884c\u653f\u5355\u4f4d\uff1a23\u4e2a\u7701\u30014\u4e2a\u76f4\u8f96\u5e02\u30012\u4e2a\u7279\u522b\u884c\u653f\u533a\u30015\u4e2a\u81ea\u6cbb\u533a\u3002<\/p><p>\u6211\u56fd\u5171\u670934\u4e2a\u7701\u7ea7\u884c\u653f\u533a\uff0c\u5176\u4e2d\uff1a<br>\u00b7 \u76f4\u8f96\u5e02\u67094\u4e2a\uff1a\u5317\u4eac\u5e02\uff08\u4eac\uff09\u3001\u5929\u6d25\u5e02\uff08\u6d25\uff09\u3001\u4e0a\u6d77\u5e02\uff08\u6caa\uff09\u3001\u91cd\u5e86\u5e02\uff08\u6e1d\uff09\u3002<br>\u00b7 \u7279\u522b\u884c\u653f\u533a\u67092\u4e2a\uff1a\u9999\u6e2f\u7279\u522b\u884c\u653f\u533a\u548c\u6fb3\u95e8\u7279\u522b\u884c\u653f\u533a\u3002<br>\u00b7 \u81ea\u6cbb\u533a\u67095\u4e2a\uff1a\u65b0\u7586\u7ef4\u543e\u5c14\u81ea\u6cbb\u533a\uff08\u65b0\uff09\u3001\u5b81\u590f\u56de\u65cf\u81ea\u6cbb\u533a\uff08\u5b81\uff09\u3001\u897f\u85cf\u81ea\u6cbb\u533a\uff08\u85cf\uff09\u3001\u5e7f\u897f\u58ee\u65cf\u81ea\u6cbb\u533a\uff08\u6842\uff09\u3001\u5185\u8499\u53e4\u81ea\u6cbb\u533a\uff08\u5185\u8499\u53e4\uff09\u3002<br>\u00b7 \u7701\u4efd\u670923\u4e2a\uff1a\u6cb3\u5317\u7701(\u5180)\u3001\u5c71\u897f\u7701(\u664b)\u3001\u8fbd\u5b81\u7701(\u8fbd)\u3001\u5409\u6797\u7701(\u5409)\u3001\u9ed1\u9f99\u6c5f\u7701(\u9ed1)\u3001\u6c5f\u82cf\u7701(\u82cf)\u3001\u6d59\u6c5f\u7701(\u6d59)\u3001\u5b89\u5fbd\u7701(\u7696)\u3001\u798f\u5efa\u7701(\u95fd)\u3001\u6c5f\u897f\u7701(\u8d63)\u3001\u5c71\u4e1c\u7701(\u9c81)\u3001\u6cb3\u5357\u7701(\u8c6b)\u3001\u6e56\u5317\u7701(\u9102)\u3001\u6e56\u5357\u7701(\u6e58\u3001)\u5e7f\u4e1c\u7701(\u7ca4)\u3001\u6d77\u5357\u7701(\u743c)\u3001\u56db\u5ddd\u7701(\u5ddd\u3001\u8700)\u3001\u8d35\u5dde\u7701(\u9ed4\u3001\u8d35)\u3001\u4e91\u5357\u7701(\u6ec7\u3001\u4e91)\u3001\u9655\u897f\u7701(\u9655\u3001\u79e6)\u3001\u7518\u8083\u7701(\u7518\u3001\u9647)\u3001\u9752\u6d77\u7701(\u9752)\u3001\u53f0\u6e7e\u7701(\u53f0)\u3002<\/p><\/blockquote>\n\n\n\n<p>\u6700\u540e\u518d\u628a\u7f51\u4e0a\u627e\u5230\u7684Java\u4ee3\u7801\u7247\u6bb5\u653e\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4f7f\u7528\uff08\u4e5f\u53ef\u4ee5\u6309\u9700\u8fdb\u884c\u5fae\u8c03\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.ArrayList;\nimport java.util.LinkedHashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class AddressResolutionUtil {\n    public static String regex = \"(?&lt;province>[^\u7701]+\u81ea\u6cbb\u533a|.*?\u7701|.*?\u884c\u653f\u533a|.*?\u5e02)(?&lt;city>[^\u5e02]+\u81ea\u6cbb\u5dde|.*?\u5730\u533a|.*?\u884c\u653f\u5355\u4f4d|.+\u76df|\u5e02\u8f96\u533a|.*?\u5e02|.*?\u53bf)(?&lt;county>[^\u53bf]+\u53bf|.+\u533a|.+\u5e02|.+\u65d7|.+\u6d77\u57df|.+\u5c9b)?(?&lt;town>[^\u533a]+\u533a|.+\u9547)?(?&lt;village>.*)\";\n    public static Pattern pattern = Pattern.compile(regex);\n\n    public static List&lt;Map&lt;String,String>> addressResolution(String address) {\n        Matcher m = pattern.matcher(address);\n        String province = null, city = null, county = null, town = null, village = null;\n        List&lt;Map&lt;String,String>> table = new ArrayList&lt;Map&lt;String,String>>();\n        Map&lt;String,String> row = null;\n        while(m.find()) {\n            row = new LinkedHashMap&lt;String,String>();\n            province = m.group(\"province\");\n            row.put(\"province\", province==null ? \"\" : province.trim());\n            city = m.group(\"city\");\n            row.put(\"city\", city==null ? \"\" : city.trim());\n            county = m.group(\"county\");\n            row.put(\"county\", county==null ? \"\" : county.trim());\n            town = m.group(\"town\");\n            row.put(\"town\", town==null ? \"\" : town.trim());\n            village = m.group(\"village\");\n            row.put(\"village\", village==null ? \"\" : village.trim());\n            table.add(row);\n        }\n        return table;\n    }\n\n    public static void main(String[] args) {\n        System.out.println(addressResolution(\"\u6e56\u5317\u7701\u6b66\u6c49\u5e02\u6d2a\u5c71\u533a\"));\n        System.out.println(addressResolution(\"\u6e56\u5317\u7701\u6069\u65bd\u571f\u5bb6\u65cf\u82d7\u65cf\u81ea\u6cbb\u5dde\u6069\u65bd\u5e02\"));\n        System.out.println(addressResolution(\"\u5317\u4eac\u5e02\u5e02\u8f96\u533a\u671d\u9633\u533a\"));\n        System.out.println(addressResolution(\"\u5185\u8499\u53e4\u81ea\u6cbb\u533a\u5174\u5b89\u76df\u79d1\u5c14\u6c81\u53f3\u7ffc\u524d\u65d7\"));\n        System.out.println(addressResolution(\"\u897f\u85cf\u81ea\u6cbb\u533a\u65e5\u5580\u5219\u5730\u533a\u65e5\u5580\u5219\u5e02\"));\n        System.out.println(addressResolution(\"\u6d77\u5357\u7701\u7701\u76f4\u8f96\u53bf\u7ea7\u884c\u653f\u5355\u4f4d\u4e2d\u6c99\u7fa4\u5c9b\u7684\u5c9b\u7901\u53ca\u5176\u6d77\u57df\"));\n        System.out.println(addressResolution(\"\u9655\u897f\u7701\u5ef6\u5b89\u5e02\u5b9d\u5854\u533a\u9ea6\u514b\u5927\u53a6\"));\n    }\n\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p><strong>java\u4ece\u5730\u5740\u4e32\u4e2d\u89e3\u6790\u63d0\u53d6\u7701\u5e02\u533a-\u5b8c\u7f8e\u5339\u914d\u4e2d\u56fd\u6240\u6709\u5730\u5740<br><\/strong> <a href=\"https:\/\/blog.csdn.net\/superSubfn\/article\/details\/80290491\">https:\/\/blog.csdn.net\/superSubfn\/article\/details\/80290491<\/a><\/p>\n\n\n\n<p>java \u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7701\u3001\u5e02\u3001\u533a\u3001\u9547\u3001\u4e61\u7b49\u533a\u57df\u540d\u79f0\uff08\u5305\u542b\u5c11\u6570\u6c11\u65cf\u5730\u533a\uff09<br> <a href=\"https:\/\/blog.csdn.net\/qq_40083897\/article\/details\/83048587\">https:\/\/blog.csdn.net\/qq_40083897\/article\/details\/83048587<\/a><\/p>\n\n\n\n<p>\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5207\u5272\u8be6\u7ec6\u5730\u5740\u4e2d\u7684\u7701\u3001\u5e02\u3001\u533a<br> <a href=\"https:\/\/blog.csdn.net\/qq_38584262\/article\/details\/86302509\">https:\/\/blog.csdn.net\/qq_38584262\/article\/details\/86302509<\/a><\/p>\n\n\n\n<p>JAVA\u5b9e\u73b0\u5730\u5740\u89e3\u6790\u529f\u80fd<br> <a href=\"https:\/\/blog.csdn.net\/renfng\/article\/details\/94738164\">https:\/\/blog.csdn.net\/renfng\/article\/details\/94738164<\/a><\/p>\n\n\n\n<p>\u4e2d\u56fd\u5404\u7701\u4efd\u57ce\u5e02\u5217\u8868<br> <a href=\"http:\/\/www.maps7.com\/china_province.php\">http:\/\/www.maps7.com\/china_province.php<\/a><\/p>\n\n\n\n<p>Java \u6b63\u5219\u8868\u8fbe\u5f0f<br> <a href=\"https:\/\/www.runoob.com\/java\/java-regular-expressions.html\">https:\/\/www.runoob.com\/java\/java-regular-expressions.html<\/a><\/p>\n\n\n\n<p>JAVA\u6b63\u5219\u8868\u8fbe\u5f0f\u8bed\u6cd5\u793a\u4f8b\u4e0e\u8bed\u6cd5\u5927\u5168<br> <a href=\"https:\/\/www.w3cschool.cn\/regexp\/x9hf1pq9.html\">https:\/\/www.w3cschool.cn\/regexp\/x9hf1pq9.html<\/a><\/p>\n\n\n\n<p><strong>[\u75af\u72c2Java]\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\u6355\u83b7\u7ec4\u3001\u53cd\u5411\u5f15\u7528\u3001\u6355\u83b7\u7ec4\u547d\u540d<br><\/strong> <a href=\"https:\/\/blog.csdn.net\/Lirx_Tech\/article\/details\/51721491\">https:\/\/blog.csdn.net\/Lirx_Tech\/article\/details\/51721491<\/a><\/p>\n\n\n\n<p>\u6df1\u5165\u5165\u95e8\u6b63\u5219\u8868\u8fbe\u5f0f\uff08java\uff09 &#8211; \u547d\u540d\u6355\u83b7<br> <a href=\"https:\/\/blog.csdn.net\/su1216\/article\/details\/49407381\">https:\/\/blog.csdn.net\/su1216\/article\/details\/49407381<\/a><\/p>\n\n\n\n<p><strong>Java \u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6355\u83b7\u7ec4(capture group)<\/strong><br> <a href=\"https:\/\/www.runoob.com\/w3cnote\/java-capture-group.html\">https:\/\/www.runoob.com\/w3cnote\/java-capture-group.html<\/a><\/p>\n\n\n\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6355\u83b7\u7ec4\uff08Java\uff09<br> <a href=\"https:\/\/www.cnblogs.com\/lyy-blog\/p\/9817361.html\">https:\/\/www.cnblogs.com\/lyy-blog\/p\/9817361.html<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u6700\u8fd1\u5bf9\u8fd9\u4e00\u5757\u7684\u5185\u5bb9\u6bd4\u8f83\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u6536\u96c6\u6574\u7406\u4e86\u4e00\u4e9b\u8fd9\u65b9\u9762\u7684\u5185\u5bb9\uff0c\u65b9\u4fbf\u4ee5\u540e\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,12],"tags":[377,1576,1044],"class_list":["post-4810","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-tools","tag-regex","tag-1576","tag-1044"],"views":13481,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=4810"}],"version-history":[{"count":4,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4810\/revisions"}],"predecessor-version":[{"id":4844,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/4810\/revisions\/4844"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=4810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=4810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=4810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}