\n4<\/td>\n | (\\d{2})<\/td>\n | 25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\npublic static final String DATE_STRING = \"2017-04-25\";\r\npublic static final String P_COMM = \"(\\\\d{4})-((\\\\d{2})-(\\\\d{2}))\";\r\n \r\nPattern pattern = Pattern.compile(P_COMM);\r\nMatcher matcher = pattern.matcher(DATE_STRING);\r\nmatcher.find();\/\/\u5fc5\u987b\u8981\u6709\u8fd9\u53e5\r\nSystem.out.printf(\"\\nmatcher.group(0) value:%s\", matcher.group(0));\r\nSystem.out.printf(\"\\nmatcher.group(1) value:%s\", matcher.group(1));\r\nSystem.out.printf(\"\\nmatcher.group(2) value:%s\", matcher.group(2));\r\nSystem.out.printf(\"\\nmatcher.group(3) value:%s\", matcher.group(3));\r\nSystem.out.printf(\"\\nmatcher.group(4) value:%s\", matcher.group(4));<\/pre>\n\u547d\u540d\u6355\u83b7\u7ec4<\/strong><\/div>\n\u6bcf\u4e2a\u4ee5\u5de6\u62ec\u53f7\u5f00\u59cb\u7684\u6355\u83b7\u7ec4\uff0c\u90fd\u7d27\u8ddf\u7740 ?\uff0c\u800c\u540e\u624d\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n \u5bf9\u4e8e\u65f6\u95f4\u5b57\u7b26\u4e32\uff1a2017-04-25\uff0c\u8868\u8fbe\u5f0f\u5982\u4e0b:<\/p>\n (?\\\\d{4})-(?(?\\\\d{2})-(?\\\\d{2}))<\/date><\/month><\/md><\/year><\/pre>\n\u6709 4 \u4e2a\u547d\u540d\u7684\u6355\u83b7\u7ec4\uff0c\u5206\u522b\u662f:<\/p>\n \n\n\n\u7f16\u53f7<\/th>\n | \u540d\u79f0<\/th>\n | \u6355\u83b7\u7ec4<\/th>\n | \u5339\u914d<\/th>\n<\/tr>\n<\/thead>\n | \n\n0<\/td>\n | 0<\/td>\n | (?\\d{4})-(?(?\\d{2})-(?\\d{2}))<\/td>\n | 2017-04-25<\/td>\n<\/tr>\n | \n1<\/td>\n | year<\/td>\n | (?\\d{4})-<\/td>\n | 2017<\/td>\n<\/tr>\n | \n2<\/td>\n | md<\/td>\n | (?(?\\d{2})-(?\\d{2}))<\/td>\n | 04-25<\/td>\n<\/tr>\n | \n3<\/td>\n | month<\/td>\n | (?\\d{2})<\/td>\n | 04<\/td>\n<\/tr>\n | \n4<\/td>\n | date<\/td>\n | (?\\d{2})<\/td>\n | 25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u547d\u540d\u7684\u6355\u83b7\u7ec4\u540c\u6837\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7f16\u53f7\u83b7\u53d6\u76f8\u5e94\u503c\u3002<\/p>\n public static final String P_NAMED = \"(?\\\\d{4})-(?(?\\\\d{2})-(?\\\\d{2}))\";\r\npublic static final String DATE_STRING = \"2017-04-25\";\r\n \r\nPattern pattern = Pattern.compile(P_NAMED);\r\nMatcher matcher = pattern.matcher(DATE_STRING);\r\nmatcher.find();\r\nSystem.out.printf(\"\\n===========\u4f7f\u7528\u540d\u79f0\u83b7\u53d6=============\");\r\nSystem.out.printf(\"\\nmatcher.group(0) value:%s\", matcher.group(0));\r\nSystem.out.printf(\"\\n matcher.group('year') value:%s\", matcher.group(\"year\"));\r\nSystem.out.printf(\"\\nmatcher.group('md') value:%s\", matcher.group(\"md\"));\r\nSystem.out.printf(\"\\nmatcher.group('month') value:%s\", matcher.group(\"month\"));\r\nSystem.out.printf(\"\\nmatcher.group('date') value:%s\", matcher.group(\"date\"));\r\nmatcher.reset();\r\nSystem.out.printf(\"\\n===========\u4f7f\u7528\u7f16\u53f7\u83b7\u53d6=============\");\r\nmatcher.find();\r\nSystem.out.printf(\"\\nmatcher.group(0) value:%s\", matcher.group(0));\r\nSystem.out.printf(\"\\nmatcher.group(1) value:%s\", matcher.group(1));\r\nSystem.out.printf(\"\\nmatcher.group(2) value:%s\", matcher.group(2));\r\nSystem.out.printf(\"\\nmatcher.group(3) value:%s\", matcher.group(3));\r\nSystem.out.printf(\"\\nmatcher.group(4) value:%s\", matcher.group(4));<\/date><\/month><\/md><\/year><\/pre>\nPS:\u975e\u6355\u83b7\u7ec4<\/strong><\/div>\n\u5728\u5de6\u62ec\u53f7\u540e\u7d27\u8ddf ?:\uff0c\u800c\u540e\u518d\u52a0\u4e0a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6784\u6210\u975e\u6355\u83b7\u7ec4 (?:Expression)\u3002<\/p>\n \u5bf9\u4e8e\u65f6\u95f4\u5b57\u7b26\u4e32\uff1a2017-04-25\uff0c\u8868\u8fbe\u5f0f\u5982\u4e0b:<\/p>\n (?:\\\\d{4})-((\\\\d{2})-(\\\\d{2}))<\/pre>\n\u8fd9\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u867d\u7136\u6709\u56db\u4e2a\u5de6\u62ec\u53f7\uff0c\u7406\u8bba\u4e0a\u6709 4 \u4e2a\u6355\u83b7\u7ec4\u3002\u4f46\u662f\u7b2c\u4e00\u7ec4 (?:\\d{4})\uff0c\u5176\u5b9e\u662f\u88ab\u5ffd\u7565\u7684\u3002\u5f53\u4f7f\u7528 matcher.group(4) \u65f6\uff0c\u7cfb\u7edf\u4f1a\u62a5\u9519\u3002<\/p>\n \n\n\n\u7f16\u53f7<\/th>\n | \u6355\u83b7\u7ec4<\/th>\n | \u5339\u914d<\/th>\n<\/tr>\n<\/thead>\n | \n\n0<\/td>\n | (\\d{4})-((\\d{2})-(\\d{2}))<\/td>\n | 2017-04-25<\/td>\n<\/tr>\n | \n1<\/td>\n | ((\\d{2})-(\\d{2}))<\/td>\n | 04-25<\/td>\n<\/tr>\n | \n2<\/td>\n | (\\d{2})<\/td>\n | 04<\/td>\n<\/tr>\n | \n3<\/td>\n | (\\d{2})<\/td>\n | 25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u603b\u7ed3<\/strong><\/div>\n\n- \u666e\u901a\u6355\u83b7\u7ec4\u4f7f\u7528\u65b9\u4fbf\uff1b<\/li>\n
- \u547d\u540d\u6355\u83b7\u7ec4\u4f7f\u7528\u6e05\u6670\uff1b<\/li>\n
- \u975e\u6355\u83b7\u7ec4\u76ee\u524d\u5728\u9879\u76ee\u4e2d\u8fd8\u6ca1\u6709\u7528\u6b66\u4e4b\u5730\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"
Java \u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6355\u83b7\u7ec4\u5206\u4e3a\uff1a \u666e\u901a\u6355\u83b7\u7ec4(Expression) \u547d\u540d\u6355\u83b7\u7ec4(?Expression) […]<\/p>\n","protected":false},"author":1470,"featured_media":199454,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-199445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/199445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=199445"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/199445\/revisions"}],"predecessor-version":[{"id":199664,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/199445\/revisions\/199664"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/199454"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=199445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=199445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=199445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} | | |