{"id":1713,"date":"2019-06-03T12:00:09","date_gmt":"2019-06-03T03:00:09","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=1713"},"modified":"2025-10-06T17:41:17","modified_gmt":"2025-10-06T08:41:17","slug":"java-pattern","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/java-pattern","title":{"rendered":"Java\u306ePattern\u3068\u306f\uff1f\u6b63\u898f\u8868\u73fe\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u8868\u3059\u30af\u30e9\u30b9\u300cPattern\u300d\u3092\u89e3\u8aac"},"content":{"rendered":"<p><strong>Java\u3067Pattern\u3068\u8a00\u3048\u3070\u3001\u6b63\u898f\u8868\u73fe(Regular Expression)\u3067\u4f7f\u3046\u30af\u30e9\u30b9\u306ejava.util.regex.Pattern\u3092\u6307\u3059\u306e\u304c\u666e\u901a\u3067\u3057\u3087\u3046\u3002\u3053\u306ePattern\u3068\u306f\u3001Java\u3067\u6b63\u898f\u8868\u73fe\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u8868\u3059\u30af\u30e9\u30b9\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u3092\u3054\u89a7\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001<span>Java<\/span>\u3067\u306e\u6b63\u898f\u8868\u73fe\u306b\u8208\u5473\u30fb\u95a2\u5fc3\u3092\u304a\u6301\u3061\u306a\u306e\u3060\u3068\u601d\u3044\u307e\u3059\u3002\u305b\u3063\u304b\u304f\u3067\u3059\u306e\u3067\u3001<span>Pattern<\/span>\u3092\u901a\u3058\u3066<span>Java<\/span>\u3067\u306e\u6b63\u898f\u8868\u73fe\u306e\u4f7f\u3044\u65b9\u3092\u5b66\u3073\u307e\u305b\u3093\u304b<span>? <\/span>\u7d76\u5bfe\u306b\u5f79\u306b\u7acb\u3061\u307e\u3059\u3088<span>!!<\/span><\/p>\n<p>\u6b63\u898f\u8868\u73fe\u306e\u77e5\u8b58\u306f\u3001\u6587\u5b57\u5217\u691c\u7d22\u3084\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u4f5c\u696d\u52b9\u7387\u3092\u3068\u3066\u3082\u5411\u4e0a\u3055\u305b\u307e\u3059\u3002\u6b63\u898f\u8868\u73fe\u306f\u3001<span>Java<\/span>\u306b\u9650\u3089\u305a\u5927\u62b5\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u540c\u3058\u3088\u3046\u306b\u4f7f\u3048\u307e\u3059\u306e\u3067\u3001\u3069\u3053\u304b\u3067\u304d\u3061\u3093\u3068\u5b66\u3079\u3070\u4e00\u751f\u3082\u306e\u306e\u77e5\u8b58\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u6b63\u898f\u8868\u73fe\u306e\u521d\u5fc3\u8005\u5411\u3051\u306b\u3001<span>Java<\/span>\u3067\u306e\u6b63\u898f\u8868\u73fe\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u901a\u3058\u3066\u3001\u6b63\u898f\u8868\u73fe\u3067\u306f\u3069\u3046\u3044\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u304b\u3092\u304a\u4f1d\u3048\u3057\u307e\u3059\u3002\u3059\u3050\u306b\u4f7f\u3048\u308b\u4fbf\u5229\u306a\u30d1\u30bf\u30fc\u30f3\u306e\u30b5\u30f3\u30d7\u30eb\u3082\u3054\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b\u3053\u306e\u8a18\u4e8b\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u3001<span>Java 12<\/span>\u306e\u74b0\u5883\u3067\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#JavaPattern\">\uff11\uff0e\u3010Java\u3011Pattern\u306f\u6b63\u898f\u8868\u73fe\u306e\u300c\u30d1\u30bf\u30fc\u30f3\u300d<\/a><ul><li><a href=\"#i\">\uff11-\uff11\uff0e\u6b63\u898f\u8868\u73fe\u3068\u306f\u6587\u5b57\u5217\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u3053\u3068<\/a><\/li><li><a href=\"#-JavaPatternMatcher\">\uff11-\uff12\uff0eJava\u3067\u306e\u6b63\u898f\u8868\u73fe\u306fPattern\u3068Matcher\u3092\u4f7f\u3046<\/a><\/li><li><a href=\"#-Pattern\">\uff11-\uff13\uff0ePattern\u306f\u6b63\u898f\u8868\u73fe\u3092\u300c\u30b3\u30f3\u30d1\u30a4\u30eb\u300d\u3057\u3066\u4f5c\u308b<\/a><\/li><li><a href=\"#-PatternMatcher\">\uff11-\uff14\uff0ePattern\u306fMatcher\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046<\/a><\/li><li><a href=\"#-Pattern-2\">\uff11-\uff15\uff0ePattern\u306f\u4f7f\u3044\u307e\u308f\u3057\u304c\u3067\u304d\u308b<\/a><\/li><li><a href=\"#-Pattern-3\">\uff11-\uff16\uff0ePattern\u306e\u305d\u306e\u4ed6\u306e\u30e1\u30bd\u30c3\u30c9<\/a><\/li><\/ul><\/li><li><a href=\"#Java\">\uff12\uff0e\u3010Java\u3011\u6b63\u898f\u8868\u73fe\u306e\u4f5c\u308a\u65b9<\/a><ul><li><a href=\"#i-2\">\uff12-\uff11\uff0e\u3010\u91cd\u8981\u3011\u6b63\u898f\u8868\u73fe\u306e\u57fa\u672c\u306e\u30ad<\/a><\/li><li><a href=\"#i-3\">\uff12-\uff12\uff0e\u6b63\u898f\u8868\u73fe\u3067\u306e\u7279\u6b8a\u6587\u5b57\u306f\u30a8\u30b9\u30b1\u30fc\u30d7\u304c\u5fc5\u8981<\/a><\/li><li><a href=\"#i-4\">\uff12-\uff13\uff0e\u6b63\u898f\u8868\u73fe\u306e\u4f8b<\/a><\/li><\/ul><\/li><li><a href=\"#Matcher\">\uff13\uff0e\u3010\u53c2\u8003\u3011Matcher\u306e\u7c21\u5358\u306a\u7d39\u4ecb<\/a><ul><li><a href=\"#-Matchermatches\">\uff13-\uff11\uff0eMatcher.matches\u3067\u5168\u4f53\u304c\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/a><\/li><li><a href=\"#-MatcherlookingAt\">\uff13-\uff12\uff0eMatcher.lookingAt\u3067\u5148\u982d\u304b\u3089\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/a><\/li><li><a href=\"#-Matcherfind\">\uff13-\uff13\uff0eMatcher.find\u3067\u9014\u4e2d\u3067\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/a><\/li><li><a href=\"#-MatcherreplaceAllreplaceFirst\">\uff13-\uff14\uff0eMatcher.replaceAll\/replaceFirst\u3067\u4e00\u81f4\u90e8\u5206\u3092\u5165\u308c\u66ff\u3048\u308b<\/a><\/li><li><a href=\"#-Matchergroupgroups\">\uff13-\uff15\uff0eMatcher.group\/groups\u3067\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u7d50\u679c\u3092\u53d6\u308a\u51fa\u3059<\/a><\/li><\/ul><\/li><li><a href=\"#i-5\">\uff14\uff0e\u6b63\u898f\u8868\u73fe\u306e\u6d3b\u7528\u4f8b<\/a><ul><li><a href=\"#i-6\">\uff14-\uff11\uff0e\u7a7a\u767d\u3084\u533a\u5207\u308a\u6587\u5b57\u306a\u3069\u306e\u9664\u53bb\u3001\u7f6e\u63db<\/a><\/li><li><a href=\"#i-7\">\uff14-\uff12\uff0e\u6587\u5b57\u5217\u306e\u8981\u7d20\u5206\u89e3(\u7a7a\u767d\u30fb\u30ab\u30f3\u30de\u533a\u5207\u308a\u306a\u3069)<\/a><\/li><li><a href=\"#i-8\">\uff14-\uff13\uff0e\u6587\u5b57\u5217\u306e\u30de\u30b9\u30af<\/a><\/li><li><a href=\"#i-9\">\uff14-\uff14\uff0e\u533a\u5207\u308a\u6587\u5b57\u306e\u7d71\u4e00<\/a><\/li><li><a href=\"#i-10\">\uff14-\uff15\uff0e\u97f3\u5f15\u304d\u306e\u7d71\u4e00<\/a><\/li><li><a href=\"#-HTMLXML\">\uff14-\uff16\uff0eHTML\/XML\u4e2d\u306e\u5c5e\u6027\u5024\u306e\u524a\u9664<\/a><\/li><li><a href=\"#i-11\">\uff14-\uff17\uff0e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u89e3\u6790<\/a><\/li><li><a href=\"#i-12\">\uff14-\uff18\uff0e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u6587\u5b57\u5217\u7f6e\u63db<\/a><\/li><\/ul><\/li><li><a href=\"#Pattern\">\uff15\uff0e\u3010\u767a\u5c55\u3011Pattern\u306e\u4fbf\u5229\u306a\u6a5f\u80fd\u305f\u3061<\/a><ul><li><a href=\"#i-13\">\uff15-\uff11\uff0e\u3010\u91cd\u8981\u3011\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u53d6\u308a\u51fa\u3059\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc<\/a><\/li><li><a href=\"#i-14\">\uff15-\uff12\uff0e\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u7f6e\u63db\u6642\u306b$\u3067\u53c2\u7167\u3059\u308b<\/a><\/li><li><a href=\"#i-15\">\uff15-\uff13\uff0e\u6700\u77ed\u4e00\u81f4\u3092\u3055\u305b\u3066\u307f\u308b<\/a><\/li><li><a href=\"#i-16\">\uff15-\uff14\uff0e\u3010\u767a\u5c55\u3011\u52d5\u4f5c\u3092\u5909\u3048\u308b\u30d5\u30e9\u30b0\u3092\u4f7f\u3063\u3066\u307f\u308b<\/a><\/li><li><a href=\"#i-17\">\uff15-\uff15\uff0e\u3010\u767a\u5c55\u3011\u5f8c\u65b9\u53c2\u7167\u3092\u3057\u3066\u307f\u308b<\/a><\/li><li><a href=\"#i-18\">\uff15-\uff16\uff0e\u3010\u767a\u5c55\u3011\u5148\u8aad\u307f\u30fb\u5f8c\u8aad\u307f\u3092\u3057\u3066\u307f\u308b<\/a><\/li><\/ul><\/li><li><a href=\"#i-19\">\uff16\uff0e\u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"JavaPattern\">\uff11\uff0e\u3010Java\u3011Pattern\u306f\u6b63\u898f\u8868\u73fe\u306e\u300c\u30d1\u30bf\u30fc\u30f3\u300d<\/span><\/h2>\n<h3><span id=\"i\">\uff11-\uff11\uff0e\u6b63\u898f\u8868\u73fe\u3068\u306f\u6587\u5b57\u5217\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u3053\u3068<\/span><\/h3>\n<p>\u305d\u3082\u305d\u3082\u6b63\u898f\u8868\u73fe<span>(Regular Expression)<\/span>\u3068\u306f\u30ca\u30cb\u30e2\u30ce\u304b\u3068\u3044\u3046\u3068\u3001\u6587\u5b57\u5217\u304c\u6301\u3063\u3066\u3044\u308b\u300c\u30d1\u30bf\u30fc\u30f3\u300d\u3092\u5171\u901a\u3057\u305f\u8a00\u3044\u65b9\u3067\u8868\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u307e\u3068\u3081\u3066\u4f7f\u3048\u308c\u3070\u3059\u3054\u304f\u4fbf\u5229\u3058\u3083\u306a\u3044<span>? <\/span>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u8eab\u306e\u56de\u308a\u306b\u3042\u308b\u3044\u308d\u3044\u308d\u306a\u6587\u5b57\u5217\u306f\u3001\u30eb\u30fc\u30eb\u3084\u30d1\u30bf\u30fc\u30f3\u3092\u6301\u3064\u3082\u306e\u304c\u591a\u3044\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001\u90f5\u4fbf\u756a\u53f7\u3063\u3066\u3069\u3093\u306a\u3082\u306e<span>?<\/span>\u3068\u805e\u304b\u308c\u305f\u3089\u3001\u300c<span>3<\/span>\u6841\u306e\u6570\u5b57\u3068<span>4<\/span>\u6841\u306e\u6570\u5b57\u304c<span>&#8220;-&#8220;<\/span>\u3067\u3064\u306a\u304c\u3063\u305f\u3082\u306e\u300d\u3068\u30d1\u30bf\u30fc\u30f3\u3092\u8aac\u660e\u3067\u304d\u307e\u3059\u3088\u306d\u3002<\/p>\n<p>\u305d\u3093\u306a\u6587\u5b57\u5217\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u3001\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u304c\u308f\u304b\u308b\u66f8\u304d\u65b9\u306b\u3057\u305f\u306e\u304c\u6b63\u898f\u8868\u73fe\u3067\u3059\u3002\u30d1\u30bf\u30fc\u30f3\u3092\u6b63\u898f\u8868\u73fe\u3067\u66f8\u304d\u3055\u3048\u3059\u308c\u3070\u3001\u4f55\u304b\u306e\u6587\u5b57\u5217\u304c\u305d\u306e\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u3059\u308b\u304b\u306f\u3001\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306f\u3059\u3050\u3055\u307e\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4eba\u9593\u304c\u6301\u3064\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u51fa\u3059\u80fd\u529b\u3068\u3001\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u304c\u6301\u3064\u6587\u53e5\u3072\u3068\u3064\u8a00\u308f\u305a\u306b\u5927\u91cf\u30fb\u9ad8\u901f\u306b\u30ac\u30f3\u30ac\u30f3\u51e6\u7406\u3067\u304d\u308b\u80fd\u529b\u3002\u3053\u306e\u4e8c\u3064\u3092\u3042\u308f\u305b\u308c\u3070\u3001\u5927\u91cf\u306e\u6587\u5b57\u5217\u3092\u76f8\u624b\u306b\u3057\u305f\u4f5c\u696d\u3067\u3042\u3063\u3066\u3082\u3001\u6016\u3044\u3082\u306e\u306a\u3057\u306a\u306e\u3067\u3059\u3002<\/p>\n<h3><span id=\"-JavaPatternMatcher\">\uff11-\uff12\uff0eJava\u3067\u306e\u6b63\u898f\u8868\u73fe\u306f<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u3092\u4f7f\u3046<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306f\u4e16\u306e\u4e2d\u306b\u3042\u308b\u307b\u3068\u3093\u3069\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u4f7f\u3048\u307e\u3059\u3002\u3082\u3061\u308d\u3093<span>Java<\/span>\u3067\u3082\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3048\u307e\u3059\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u6587\u6cd5\u306b\u306f\u7d44\u307f\u8fbc\u307e\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001<span>Java<\/span>\u3067\u306f\u6b63\u898f\u8868\u73fe\u306e\u305f\u3081\u306e\u30af\u30e9\u30b9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>Java\u306e\u6b63\u898f\u8868\u73fe\u3067\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8<span>java.util.regex<\/span>\u306b\u3042\u308b<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u3068\u3044\u3046\u30af\u30e9\u30b9\u3092\u4f7f\u3044\u307e\u3059\u3002<span>Pattern<\/span>\u304c\u6b63\u898f\u8868\u73fe\u306e\u300c\u30d1\u30bf\u30fc\u30f3\u300d\u3092\u8868\u3057\u3001<span>Matcher<\/span>\u304c\u691c\u67fb\u3057\u305f\u3044\u6587\u5b57\u5217\u3068\u6b63\u898f\u8868\u73fe\u3068\u306e\u300c\u30de\u30c3\u30c1\u30f3\u30b0\u300d\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<blockquote>\n<p>java.util.regex (Java SE 11 &amp; JDK 11)<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/package-summary.html\">https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/package-summary.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Pattern (Java SE 11 &amp; JDK 11)<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/Pattern.html\">https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/Pattern.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Matcher (Java SE 11 &amp; JDK 11)<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/Matcher.html\">https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/util\/regex\/Matcher.html<\/a><\/p>\n<\/blockquote>\n<p>\u3061\u306a\u307f\u306b\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306e<span>regex<\/span>\u306f\u3001<span>REGular EXpression<\/span>\u306e\u7565\u3067\u3059\u3002<span>regex<\/span>\u3068\u304b<span>re<\/span>\u306f\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u3082\u3088\u304f\u4f7f\u308f\u308c\u308b\u7565\u79f0\u3067\u3059\u306e\u3067\u3001\u899a\u3048\u3066\u304a\u304f\u3068\u300c\u3042\u3042\u3001\u6b63\u898f\u8868\u73fe\u306b\u95a2\u4fc2\u3059\u308b\u4f55\u304b\u3060\u306d\u300d\u3068\u3059\u3050\u308f\u304b\u308a\u307e\u3059\u3088\u3002<\/p>\n<h3><span id=\"-Pattern\">\uff11-\uff13\uff0ePattern\u306f\u6b63\u898f\u8868\u73fe\u3092\u300c\u30b3\u30f3\u30d1\u30a4\u30eb\u300d\u3057\u3066\u4f5c\u308b<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306f\u305d\u308c\u3060\u3051\u3067\u4e00\u3064\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u3082\u3044\u3048\u308b\u9ad8\u6a5f\u80fd\u30fb\u8907\u96d1\u306a\u3082\u306e\u3067\u3059\u3002\u3067\u3059\u306e\u3067\u3001\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3046\u6642\u306b\u306f\u3001\u4e8b\u524d\u306b\u6b63\u898f\u8868\u73fe\u306e\u300c\u30b3\u30f3\u30d1\u30a4\u30eb\u300d\u3092\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304c\u591a\u3044\u306e\u3067\u3059\u3002<span>Java<\/span>\u306f\u305d\u306e\u4ef2\u9593\u3067\u3059\u3002<\/p>\n<p>Java\u3067\u6b63\u898f\u8868\u73fe\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u306b\u306f\u3001<span>java.util.regex.Pattern<\/span>\u306e\u30e1\u30bd\u30c3\u30c9<span>compile<\/span>\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<span>Pattern.compile<\/span>\u304b\u3089\u306f<span>Pattern<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u623b\u308a\u307e\u3059\u3002\u6b63\u898f\u8868\u73fe\u306e\u69cb\u6587\u3069\u304a\u308a\u3067\u306a\u3044\u3068\u3001\u4f8b\u5916\u304c<span>throw<\/span>\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Java 11\u306e\u65e5\u672c\u8a9e\u7248Javadoc\u3088\u308a\u629c\u7c8b\r\npublic static Pattern compile(String regex)\r\n\t\u6307\u5b9a\u3055\u308c\u305f\u6b63\u898f\u8868\u73fe\u3092\u30d1\u30bf\u30fc\u30f3\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002\r\n\u30d1\u30e9\u30e1\u30fc\u30bf:\r\n\tregex - \u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u308b\u8868\u73fe\r\n\u623b\u308a\u5024:\r\n\t\u30d1\u30bf\u30fc\u30f3\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u6307\u5b9a\u3055\u308c\u305f\u6b63\u898f\u8868\u73fe\r\n\u4f8b\u5916:\r\n\tPatternSyntaxException - \u8868\u73fe\u306e\u69cb\u6587\u304c\u7121\u52b9\u3067\u3042\u308b\u5834\u5408<\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6b63\u898f\u8868\u73fe\u306e\u6587\u5b57\u5217\u3092\u5f15\u6570\u306b<span>compile<\/span>\u3092\u547c\u3073\u51fa\u3059\u3068\u3001\u6b63\u898f\u8868\u73fe\u306e<span>Pattern<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u623b\u308a\u307e\u3059\u3002\u306a\u304a\u3001\u5f8c\u8005\u306f\u6b63\u898f\u8868\u73fe\u3068\u3057\u3066\u6b63\u3057\u3044\u69cb\u6587\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u5b9f\u884c\u6642\u306b<span>PatternSyntaxException<\/span>\u304c<span>throw<\/span>\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern1 = Pattern.compile(\"[a-z]\"); \/\/ \u5c0f\u6587\u5b57\u306e\u82f1\u5b57\u2192OK\r\nPattern pattern2 = Pattern.compile(\"[\"); \/\/ [\u304c\u9589\u3058\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u69cb\u6587\u3068\u3057\u3066NG<\/pre>\n<p>\u306a\u304a\u3001<span>Pattern<\/span>\u306f\u5916\u90e8\u304b\u3089<span>new<\/span>\u3057\u3066\u4f5c\u308c\u306a\u3044\u306e\u3067<span>(<\/span>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u306a\u3044<span>)<\/span>\u3001\u5fc5\u305a<span>Pattern.compile<\/span>\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3><span id=\"-PatternMatcher\">\uff11-\uff14\uff0ePattern\u306f<span>Matcher<\/span>\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046<\/span><\/h3>\n<p>Pattern\u306f\u6b63\u898f\u8868\u73fe\u3092\u8868\u3057\u3066\u3044\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002\u3067\u3082\u3001<span>Pattern<\/span>\u3060\u3051\u3067\u306f\u6587\u5b57\u5217\u3068\u306e\u30de\u30c3\u30c1\u30f3\u30b0\u306f\u51fa\u6765\u307e\u305b\u3093\u3002\u6587\u5b57\u5217\u3068\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u3059\u308b\u306b\u306f\u3001<span>Pattern.matcher<\/span>\u3067\u5f97\u3089\u308c\u308b<span>Matcher<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Java 11\u306e\u65e5\u672c\u8a9e\u7248Javadoc\u3088\u308a\u629c\u7c8b\r\npublic Matcher matcher(CharSequence input)\r\n\t\u6307\u5b9a\u3055\u308c\u305f\u5165\u529b\u3068\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u30de\u30c3\u30c1\u3059\u308b\u6b63\u898f\u8868\u73fe\u30a8\u30f3\u30b8\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\r\n\u30d1\u30e9\u30e1\u30fc\u30bf:\r\n\tinput - \u30de\u30c3\u30c1\u3055\u308c\u308b\u6587\u5b57\u30b7\u30fc\u30b1\u30f3\u30b9\r\n\u623b\u308a\u5024:\r\n\t\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u65b0\u3057\u3044\u6b63\u898f\u8868\u73fe\u30a8\u30f3\u30b8\u30f3<\/pre>\n<p>Pattern\u3068\u306f\u6b63\u898f\u8868\u73fe\u305d\u306e\u3082\u306e\u3067\u3001<span>Matcher<\/span>\u3068\u306f\u4f55\u304b\u306e\u6587\u5b57\u5217\u3068\u306e\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u884c\u3046\u3082\u306e<span>(match + er)<\/span>\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3044\u5206\u3051\u307e\u3059\u304c\u3001<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u306e\u5f79\u5272\u306e\u9055\u3044\u304c\u304a\u5224\u308a\u3044\u305f\u3060\u3051\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ \u6b63\u898f\u8868\u73fe\u3092Pattern\u3068\u3057\u3066\u4f5c\u3063\u3066\u3001\r\nPattern pattern = Pattern.compile(\"[a-z]\");\r\n\/\/ \u30de\u30c3\u30c1\u3055\u305b\u305f\u3044\u6587\u5b57\u5217\u306b\u5bfe\u3059\u308bMatcher\u3092Pattern\u304b\u3089\u4f5c\u308b\r\nMatcher matcher = pattern.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\r\n\/\/ Matcher\u306b\u6b63\u898f\u8868\u73fe\u306b\u30de\u30c3\u30c1\u3059\u308b\u304b\u3092\u805e\u3044\u3066\u3001\u30de\u30c3\u30c1\u3057\u305f\u304b\u3067\u51e6\u7406\u3092\u5206\u3051\u308b\r\nif (matcher.find()) {\r\n\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\");\r\n} else {\r\n\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u305b\u3093\");\r\n}<\/pre>\n<p>Matcher\u306b\u3064\u3044\u3066\u306f\u3001\u3053\u306e\u5f8c\u3067\u7c21\u5358\u306a\u4f7f\u3044\u65b9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u30de\u30c3\u30c1\u3055\u305b\u308b\u306b\u3082\u3001\u5b8c\u5168\u4e00\u81f4\u306a\u306e\u304b\u3001\u90e8\u5206\u7684\u306a\u4e00\u81f4\u306a\u306e\u304b\u306a\u3069\u3001\u3044\u308d\u3044\u308d\u306a\u30de\u30c3\u30c1\u306e\u3055\u305b\u65b9\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u4f7f\u3044\u65b9\u306f\u899a\u3048\u3066\u304a\u304d\u305f\u3044\u3067\u3059\u306d\u3002<\/p>\n<h3><span id=\"-Pattern-2\">\uff11-\uff15\uff0ePattern\u306f\u4f7f\u3044\u307e\u308f\u3057\u304c\u3067\u304d\u308b<\/span><\/h3>\n<p>\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u4f5c\u3063\u305f<span>Pattern<\/span>\u306f\u305a\u3063\u3068\u4f7f\u3048\u307e\u3059\u3002\u3064\u307e\u308a\u3001<span>Pattern<\/span>\u3092\u4f7f\u3048\u308b\u306e\u306f\u4e00\u56de\u3053\u3063\u304d\u308a\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u3002\u3080\u3057\u308d\u3001<span>Pattern<\/span>\u306e\u4f7f\u3044\u307e\u308f\u3057\u3092\u3059\u308b\u305f\u3081\u306b\u3001<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u304c\u5225\u306e\u30af\u30e9\u30b9\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u6700\u521d\u306b\u4f5c\u3063\u305f<span>Pattern<\/span>\u3092\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u305a\u3063\u3068\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<span>Matcher<\/span>\u306f\u30eb\u30fc\u30d7\u3057\u3066\u3044\u308b\u884c\u3054\u3068\u306b<span>Pattern<\/span>\u304b\u3089\u4f5c\u308a\u76f4\u3057\u3066\u3044\u307e\u3059\u304c\u3001<span>Pattern<\/span>\u306f\u305a\u3063\u3068\u540c\u3058\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3088\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Pattern\u3060\u3051\u306f\u5148\u306bcompile\u3057\u3066\u4f5c\u3063\u3066\u304a\u3044\u3066\u3001\r\nPattern pattern = Pattern.compile(\"[a-z]\");\r\n\r\n\/\/ \u3068\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3067\u884c\u5358\u4f4d\u306b\u30eb\u30fc\u30d7\u3059\u308b\r\nfor (String line : Files.readAllLines(Paths.get(\"\/path\/to\/file.txt\"))) {\r\n\t\/\/ Matcher\u306f\u73fe\u5728\u306e\u884c\u3092\u5bfe\u8c61\u306bPattern\u304b\u3089\u751f\u6210\u3057\u3066\u3001\r\n\tMatcher matcher = pattern.matcher(line);\r\n\r\n\t\/\/ Matcher\u3067\u30de\u30c3\u30c1\u3059\u308b\u304b\u78ba\u8a8d\u3059\u308b\r\n\tif (matcher.find()) {\r\n\t\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\");\r\n\t} else {\r\n\t\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u305b\u3093\");\r\n\t}\r\n}<\/pre>\n<p>\u3082\u3061\u308d\u3093\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3082\u66f8\u3051\u307e\u3059\u3057\u52d5\u304d\u3082\u3057\u307e\u3059\u3002\u3067\u3082\u3001\u540c\u3058\u6b63\u898f\u8868\u73fe\u3092\u30eb\u30fc\u30d7\u3054\u3068\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u306e\u306f\u3044\u308d\u3044\u308d\u3068\u7121\u99c4\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002<span>Pattern<\/span>\u306f\u3001\u3042\u3089\u304b\u3058\u3081\u5148\u306b\u4f5c\u3063\u3066\u304a\u3044\u3066\u3001\u4f7f\u3044\u307e\u308f\u3059\u306e\u304c\u304a\u52e7\u3081\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ \u3068\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3067\u884c\u5358\u4f4d\u306b\u30eb\u30fc\u30d7\u3059\u308b\r\nfor (String line : Files.readAllLines(Paths.get(\"\/path\/to\/file.txt\"))) {\r\n\t\/\/ Pattern\u3092\u30eb\u30fc\u30d7\u306e\u5ea6\u306bcompile\u3057\u3066\u4f5c\u308b\u2192\u7121\u99c4!!\r\n\tPattern pattern = Pattern.compile(\"[a-z]\");\r\n\t\/\/ Matcher\u306f\u73fe\u5728\u306e\u884c\u3092\u5bfe\u8c61\u306bPattern\u304b\u3089\u751f\u6210\u3057\u3066\u3001\r\n\tMatcher matcher = pattern.matcher(line);\r\n\r\n\t\/\/ Matcher\u3067\u30de\u30c3\u30c1\u3059\u308b\u304b\u78ba\u8a8d\u3059\u308b\r\n\tif (matcher.find()) {\r\n\t\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\");\r\n\t} else {\r\n\t\tSystem.out.println(\"\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u305b\u3093\");\r\n\t}\r\n}<\/pre>\n<p>Pattern\u304c\u4f7f\u308f\u308c\u308b\u5834\u6240\u306b\u3088\u308a\u3001<span>Pattern<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4fdd\u6301\u3059\u308b\u5834\u6240\u3092\u3001\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3084\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u3069\u308c\u306b\u3059\u308b\u304b\u9078\u3079\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u3001<span>Pattern<\/span>\u306f\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u306e\u3067\u3001\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306a\u74b0\u5883\u3067\u3082\u5b89\u5168\u306b\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Pattern\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6301\u3064\u3068\u3053\u308d\u306f\u2026\r\nclass PatternSample {\r\n\t\/\/ static\u30d5\u30a3\u30fc\u30eb\u30c9\u3067\u3082\u3044\u3044\u3057\u3001\r\n\tstatic final Pattern PATTERN_FIELD = Pattern.compile(\"[a-z]\");\r\n\t\/\/ \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30d5\u30a3\u30fc\u30eb\u30c9\u3067\u3082\u3044\u3044\u3057\u3001\r\n\tfinal Pattern patternField = Pattern.compile(\"[a-z]\");\r\n\r\n\tvoid patternSample() {\r\n\t\t\/\/ \u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3068\u3057\u3066\u3082\u3044\u3044!!\r\n\t\tPattern patternLocal = Pattern.compile(\"[a-z]\");\r\n\r\n\t\t\/\/ \u3088\u304f\u4f7f\u3046Pattern\u306f\u4f7f\u3044\u307e\u308f\u3059\u306e\u304c\u304a\u52e7\u3081!!\r\n\t\tMatcher m1 = PATTERN_FIELD.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\t\tMatcher m2 = patternField.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\t\tMatcher m3 = patternLocal.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\t}\r\n}<\/pre>\n<h3><span id=\"-Pattern-3\">\uff11-\uff16\uff0ePattern\u306e\u305d\u306e\u4ed6\u306e\u30e1\u30bd\u30c3\u30c9<\/span><\/h3>\n<h4>\uff11-\uff16-\uff11\uff0ePattern.split\u3067\u6587\u5b57\u5217\u3092\u5206\u5272\u3059\u308b<\/h4>\n<p>String\u306b\u306f\u3001\u6587\u5b57\u5217\u3092\u6b63\u898f\u8868\u73fe\u3067\u6307\u5b9a\u3057\u305f\u533a\u5207\u308a\u6587\u5b57\u3067\u5206\u5272\u3059\u308b\u3001<span>String.split<\/span>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002<span>Pattern<\/span>\u306b\u306f\u3001\u305d\u308c\u3068\u540c\u3058\u52d5\u304d\u3092\u3059\u308b<span>Pattern.split<\/span>\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A-B-C-D\";\r\nPattern p = Pattern.compile(\"-\");\r\nString[] arr = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(arr)); \/\/ \u2192 [A, B, C, D]<\/pre>\n<p>Pattern.split\u306e\u3044\u3044\u3068\u3053\u308d\u306f\u3001\u8907\u6570\u306e<span>String<\/span>\u3092\u540c\u3058\u6b63\u898f\u8868\u73fe\u3067<span>split<\/span>\u3059\u308b\u5834\u5408\u3067\u3082\u3001<span>Pattern<\/span>\u306e\u751f\u6210\u304c<span>1<\/span>\u56de\u3067\u6e08\u3080\u3053\u3068\u3067\u3059\u3002\u8907\u96d1\u306a\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3046\u5834\u5408\u306a\u3069\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u6642\u9593\u3092\u5c11\u3057\u77ed\u304f\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern p = Pattern.compile(\"-\");\r\njava.util.Arrays.asList(\"A-B-C-D\", \"E-F-G-H\", \"I-J-K-L\").forEach(s -&gt; {\r\n\tString[] arr = p.split(s);\r\n\tSystem.out.println(java.util.Arrays.toString(arr));\r\n});<\/pre>\n<p>\u306a\u304a\u3001\u5206\u5272\u3059\u308b\u4f4d\u7f6e\u3092\u6307\u5b9a\u3059\u308bString.split(String, int)\u3068\u540c\u3058\u52d5\u4f5c\u3092\u3059\u308b\u3001Pattern.split(String, int)\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A-B-C-D\";\r\nPattern p = Pattern.compile(\"-\");\r\nString[] arr = p.split(s, 2);\r\nSystem.out.println(java.util.Arrays.toString(arr)); \/\/ \u2192 [A, B-C-D]<\/pre>\n<p>String.split\u306e\u8a73\u7d30\u306f\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u3054\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3088\u308d\u3057\u3051\u308c\u3070\u3054\u89a7\u306b\u306a\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n<span style=\"text-decoration:none !important; background-color:#a61e58; color:white; padding:4px 13px; font-size:12px; font-weight:bold; position:relative; top:10px; z-index:1; left:11px;\">\u95a2\u9023\u8a18\u4e8b<\/span>\n<div class=\"blog-card\"><a target=\"_blank\" href=\"https:\/\/www.bold.ne.jp\/engineer-club\/java-split\" style=\"text-decoration:none;\">\n    <div class=\"blog-card-thumbnail\"><img src='https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2018\/10\/shutterstock_568617811-600x366.jpg' alt='Java\u306esplit\u3068\u306f\uff1f\u6587\u5b57\u5217\u3092\u5206\u5272\u3059\u308bsplit\u306e\u4f7f\u3044\u65b9\u3010\u30b5\u30f3\u30d7\u30eb\u4ed8\u304d\u3011' width=160 height=98 \/><\/div>\n    <div class=\"blog-card-content\">\n        <div class=\"blog-card-title\">Java\u306esplit\u3068\u306f\uff1f\u6587\u5b57\u5217\u3092\u5206\u5272\u3059\u308bsplit\u306e\u4f7f\u3044\u65b9\u3010\u30b5\u30f3\u30d7\u30eb\u4ed8\u304d\u3011 <\/div>\n        <span style=\"font-size: 12px; font-weight: normal; position:relative; color:#666;\"><i class=\"fa fa-clock-o\"><\/i>&nbsp;2025\/09\/17<\/span>\n    <\/div>\n<div class=\"clear\"><\/div>\n<\/a><\/div>\n<h4>\uff11-\uff16-\uff12\uff0ePattern.asPredicate\/asMatchPredicate\u3067\u30de\u30c3\u30c1\u78ba\u8a8d\u7528\u306ePredicate\u3092\u4f5c\u308b<\/h4>\n<p>Java 8\u304b\u3089\u306fPattern.asPredicate\u3001Java 11\u304b\u3089\u306fPattern.asMatchPredicate\u304c\u4f7f\u3048\u307e\u3059\u3002\u3053\u308c\u3089\u306f\u3001\u305d\u308c\u305e\u308c<span>Matcher.find<\/span>\u3068<span>matches<\/span>\u3092\u5b9f\u884c\u3057\u3001\u7d50\u679c\u3092\u623b\u3059<span>Predicate<\/span>\u3092\u751f\u6210\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<p>\u3067\u3059\u306e\u3067\u3001\u300c\u3053\u306e\u6b63\u898f\u8868\u73fe\u306b\u30de\u30c3\u30c1\u3059\u308b\u304b\u3069\u3046\u304b\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3067\u304d\u308b<span>Predicate<\/span>\u3092\u3001\u304a\u624b\u8efd\u306b\u4f5c\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u6b63\u898f\u8868\u73fe\u3067\u306e\u300c\u30c1\u30a7\u30c3\u30af\u51e6\u7406\u300d\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u3066\u3001\u8272\u3005\u306a\u5834\u6240\u3078\u6301\u3061\u904b\u3076\u306e\u306b\u4f7f\u3048\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern p = Pattern.compile(\"[0-9]+\");\r\nPredicate&lt;String&gt; pr1 = p.asPredicate();\r\nPredicate&lt;String&gt; pr2 = p.asMatchPredicate();\r\n\r\n\/\/ pr1\u306fasPredicate\u3067\u4f5c\u3063\u305f\u306e\u3067\u3001\u691c\u67fb\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u306b\u6570\u5b57\u304c\u542b\u307e\u308c\u308b\u304b(=find)\u3092\u78ba\u8a8d\u3059\u308b\r\nboolean b1_1 = pr1.test(\"aaa bbb ccc 123 ddd\");\r\nboolean b1_2 = pr1.test(\"aaa bbb ccc ddd\");\r\nSystem.out.println(b1_1); \/\/ \u2192 true\r\nSystem.out.println(b1_2); \/\/ \u2192 false\r\n\r\n\/\/ pr2\u306fasMatchPredicate\u3067\u4f5c\u3063\u305f\u306e\u3067\u3001\u691c\u67fb\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u304c\u6570\u5b57\u306e\u307f\u304b(=matches)\u3092\u78ba\u8a8d\u3059\u308b\r\nboolean b2_1 = pr2.test(\"abcd 1234\");\r\nboolean b2_2 = pr2.test(\"1234\");\r\nSystem.out.println(b2_1); \/\/ \u2192 false\r\nSystem.out.println(b2_2); \/\/ \u2192 true<\/pre>\n<h2><span id=\"Java\">\uff12\uff0e\u3010Java\u3011\u6b63\u898f\u8868\u73fe\u306e\u4f5c\u308a\u65b9<\/span><\/h2>\n<h3><span id=\"i-2\">\uff12-\uff11\uff0e\u3010\u91cd\u8981\u3011\u6b63\u898f\u8868\u73fe\u306e\u57fa\u672c\u306e\u30ad<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306e\u5168\u3066\u3092\u5b8c\u74a7\u306b\u30de\u30b9\u30bf\u30fc\u3059\u308b\u306e\u306f\u96e3\u3057\u3044\u3067\u3059\u3002\u304d\u3061\u3093\u3068\u89e3\u8aac\u3059\u308b\u306a\u3089\u4e00\u518a\u306e\u5206\u539a\u3044\u672c\u306b\u306a\u308b\u304f\u3089\u3044\u3067\u3059\u3002\u3057\u304b\u3082\u3001<span>Java<\/span>\u306e\u6b63\u898f\u8868\u73fe\u306b\u306f\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u6b63\u898f\u8868\u73fe\u3068\u9055\u3046\u90e8\u5206\u3082\u3001\u5c11\u3057\u3060\u3051\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u3082\u3001\u4ee5\u4e0b\u306e\u57fa\u672c\u7684\u306a\u3082\u306e\u306f\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u540c\u3058\u306a\u306e\u3067\u3001\u5fc5\u305a\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u3055\u3089\u306b<span>Pattern<\/span>\u306e<span>Javadoc<\/span>\u306b\u3082<span>Java<\/span>\u306e\u6b63\u898f\u8868\u73fe\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u304d\u3061\u3093\u3068\u8aad\u3093\u3067\u304a\u3051\u3070\u3001\u3044\u305a\u308c\u5f79\u306b\u7acb\u3061\u307e\u3059\u3088\u3002<\/p>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">\u8a18\u53f7<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u610f\u5473<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u4f8b<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u30de\u30c3\u30c1\u3059\u308b\u3082\u306e<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">.<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u4f55\u304b\u4e00\u6587\u5b57\u306b\u30de\u30c3\u30c1\u3059\u308b<\/td>\n<td style=\"width: 25%; border-color: #000000;\">.\u3001..\u3001.+<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001ab\u3001\u3042\u3044\u3046\u3048\u304a<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">?<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304c0\u56de\u3042\u308b\u3044\u306f1\u56de\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a?<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001&#8221;&#8221;(\u7a7a\u6587\u5b57\u5217)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">+<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304c1\u56de\u4ee5\u4e0a\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a+<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001aa\u3001aaa<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">*<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304c0\u56de\u4ee5\u4e0a\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a*<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001aa\u3001aaa\u3001&#8221;&#8221;(\u7a7a\u6587\u5b57\u5217)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">[]<\/td>\n<td style=\"width: 25%; border-color: #000000;\">[]\u306e\u4e2d\u306b\u3042\u308b\u3069\u308c\u304b\u4e00\u6587\u5b57\u3001-\u3067\u7bc4\u56f2\u6307\u5b9a<\/td>\n<td style=\"width: 25%; border-color: #000000;\">[abcd]\u3001[a-z]<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001ab\u3001abcd<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">[^]<\/td>\n<td style=\"width: 25%; border-color: #000000;\">[]\u306e\u4e2d\u306b\u306a\u3044\u3069\u308c\u304b\u4e00\u6587\u5b57\u3001-\u3067\u7bc4\u56f2\u6307\u5b9a<\/td>\n<td style=\"width: 25%; border-color: #000000;\">[^abcd]\u3001[^a-z]<\/td>\n<td style=\"width: 25%; border-color: #000000;\">1\u3001<span>ABC<\/span>\u3001\u3042\u3044\u3046\u3048\u304a<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">{n}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304cn\u56de\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a{5}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">aaaaa<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">{n,}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304cn\u56de\u4ee5\u4e0a\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a{5,}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">aaaaa\u3001aaaaaa\u3001aaaaaaa<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">{,n}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304cn\u56de\u4ee5\u4e0b\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a{,5}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a\u3001aaa\u3001aaaaa<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">{m,n}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u76f4\u524d\u306e\u30d1\u30bf\u30fc\u30f3\u304cm\u56de\u4ee5\u4e0am\u56de\u4ee5\u4e0b\u7d9a\u304f<\/td>\n<td style=\"width: 25%; border-color: #000000;\">a{2,3}<\/td>\n<td style=\"width: 25%; border-color: #000000;\">aa\u3001aaa<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">|<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u3069\u3061\u3089\u304b\u306e\u30d1\u30bf\u30fc\u30f3\u306b\u4e00\u81f4\u3059\u308b<\/td>\n<td style=\"width: 25%; border-color: #000000;\">abc|123<\/td>\n<td style=\"width: 25%; border-color: #000000;\">abc\u3001123<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">()<\/td>\n<td style=\"width: 25%; border-color: #000000;\">()\u306e\u4e2d\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b<\/td>\n<td style=\"width: 25%; border-color: #000000;\">(abc|123)<\/td>\n<td style=\"width: 25%; border-color: #000000;\">abc\u3001123<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">^<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u884c\u982d<\/td>\n<td style=\"width: 25%; border-color: #000000;\">^abc<\/td>\n<td style=\"width: 25%; border-color: #000000;\">abc defg \u203babc\u304b\u3089\u59cb\u307e\u308b\u6587\u5b57\u5217<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; border-color: #000000;\">$<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u884c\u672b<\/td>\n<td style=\"width: 25%; border-color: #000000;\">xyz$<\/td>\n<td style=\"width: 25%; border-color: #000000;\">\u203bxyz\u3067\u7d42\u308f\u308b\u6587\u5b57\u5217<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9f\u969b\u306b\u306f\u3001\u3053\u308c\u3089\u3092\u7d44\u307f\u5408\u308f\u305b\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001<span>&#8220;\/&#8221;<\/span>\u533a\u5207\u308a\u3067\u306e\u5e74\u6708\u65e5\u306f<span>&#8220;[0-9]{4}\/[0-9]{2}\/[0-9]{2}&#8221;<\/span>\u3067\u3059\u3002\u3064\u307e\u308a\u3001<span>4<\/span>\u3064\u306e\u6570\u5b57\u3001<span>2<\/span>\u3064\u306e\u6570\u5b57\u3001\u3055\u3089\u306b<span>2<\/span>\u3064\u306e\u6570\u5b57\u304c<span>\/<\/span>\u3067\u533a\u5207\u3089\u308c\u3066\u3044\u308b\u3082\u306e\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3067\u3082\u3001\u3053\u308c\u3060\u3068\u5b9f\u969b\u306b\u306f\u30ab\u30ec\u30f3\u30c0\u30fc\u306b\u306f\u306a\u3044<span>13<\/span>\u6708\u3084<span>40<\/span>\u65e5\u304c<span>OK<\/span>\u306a\u306e\u3067\u3001\u5b9f\u7528\u3067\u306f\u3055\u3089\u306b\u5de5\u592b\u304c\u5fc5\u8981\u3067\u3059\u3002\u660e\u3089\u304b\u306b\u304a\u304b\u3057\u304f\u306a\u3044\u304b\u7a0b\u5ea6\u306e\u30c1\u30a7\u30c3\u30af\u3092\u6b63\u898f\u8868\u73fe\u3067\u884c\u3044\u3001\u8ffd\u52a0\u306e\u30c1\u30a7\u30c3\u30af\u306f\u5225\u306b\u66f8\u304f\u306e\u3082\u3088\u304f\u898b\u3089\u308c\u307e\u3059\u3002<\/p>\n<h3><span id=\"i-3\">\uff12-\uff12\uff0e\u6b63\u898f\u8868\u73fe\u3067\u306e\u7279\u6b8a\u6587\u5b57\u306f\u30a8\u30b9\u30b1\u30fc\u30d7\u304c\u5fc5\u8981<\/span><\/h3>\n<h4>\uff12-\uff12-\uff11\uff0e\\\u306f<span>Java<\/span>\u306e\u6587\u5b57\u5217\u3067\u306f\u7279\u5225\u306a\u610f\u5473\u3092\u6301\u3064<\/h4>\n<p>\u6b63\u898f\u8868\u73fe\u3067\u306f<span> \\ <\/span>\u304c\u7279\u5225\u306a\u610f\u5473\u3092\u6301\u3061\u307e\u3059\u3002\u3067\u3059\u304c\u3001<span>Java<\/span>\u3067\u306f\u6587\u5b57\u5217\u4e2d\u306e<span> \\ <\/span>\u306f\u6b63\u898f\u8868\u73fe\u306e\u524d\u306b\u6587\u5b57\u5217\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3092\u610f\u5473\u3059\u308b\u306e\u3067\u3001\u6b63\u898f\u8868\u73fe\u3067<span> \\ <\/span>\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f<span> \\\\ <\/span>\u3068\u3057\u3066\u3001<span>\\<\/span>\u306e\u52b9\u679c\u3092\u6253\u3061\u6d88\u3055\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ \u6b63\u898f\u8868\u73fe\u306e\u30d1\u30bf\u30fc\u30f3\u4e2d\u3067 \\s \u3084 \\w \u3084 \\d \u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u3001\\\\ \u3068\u3059\u308b\r\nString regex = \"\\\\s\\\\w\\\\d\";\r\nSystem.out.println(regex); \/\/ \u2192 \\s\\w\\d\r\nPattern pattern = Pattern.compile(regex);<\/pre>\n<p>\u3055\u3089\u306b\u9762\u5012\u306a\u306e\u306f\u3001<span>\\ <\/span>\u305d\u306e\u3082\u306e\u3092\u6b63\u898f\u8868\u73fe\u3067\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u3001<span>\\ <\/span>\u81ea\u4f53\u3092\u6b63\u898f\u8868\u73fe\u4e2d\u3067\u7279\u5225\u306a\u610f\u5473\u3092\u6301\u305f\u306a\u3044\u3088\u3046\u3001\u3055\u3089\u306b\u6253\u3061\u6d88\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u3067\u3059\u3002\u3067\u3059\u306e\u3067\u3001<span>\\\\\\\\ <\/span>\u3068<span> \\ <\/span>\u304c\u56db\u3064\u7e4b\u304c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ C:\\Windows\\Sytem32 \u304b Temp \u3092\u6307\u5b9a\u3059\u308b\u6b63\u898f\u8868\u73fe\r\n\/\/ \\ \u305d\u306e\u3082\u306e\u3092\u8868\u73fe\u3059\u308b\u306e\u306b \\\\\\\\ \u3068\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\r\nString regex = \"C:\\\\\\\\Windows\\\\\\\\(System32|Temp)\";\r\nSystem.out.println(regex); \/\/ \u2192 C:\\\\Windows\\\\(System32|Temp)\r\nPattern pattern = Pattern.compile(regex);<\/pre>\n<h4>\uff12-\uff12-\uff12\uff0e\u305d\u306e\u4ed6\u306e\u7279\u6b8a\u6587\u5b57\u3082\u305d\u306e\u307e\u307e\u4f7f\u3046\u306a\u3089\u30a8\u30b9\u30b1\u30fc\u30d7\u3059\u308b<\/h4>\n<p>\u305d\u3057\u3066\u3001\u6b63\u898f\u8868\u73fe\u3067\u306f<span> \\ <\/span>\u4ee5\u5916\u306b<span> [] {} | . + * ? () ^ $<\/span>\u306a\u3069\u3082\u7279\u5225\u306a\u610f\u5473\u3092\u6301\u3061\u307e\u3059\u304c\u3001\u3053\u308c\u3089\u3082\u305f\u3060\u306e\u6587\u5b57\u3068\u3057\u305f\u3044\u5834\u5408\u306f\u3001<span>\\ <\/span>\u3067\u30a8\u30b9\u30b1\u30fc\u30d7\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ \u6b63\u898f\u8868\u73fe\u4e0a\u3067\u306e\u7279\u6b8a\u6587\u5b57\u3092\u305d\u306e\u307e\u307e\u4f7f\u3044\u305f\u3044\u306a\u3089\u3001\\ \u3067\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u304c\u5fc5\u8981\r\nString regex = \"\\\\[\\\\]\\\\{\\\\}\\\\|\\\\.\\\\+\\\\*\\\\?\\\\(\\\\)\\\\^\\\\$\";\r\nSystem.out.println(regex); \/\/ \u2192 \\[\\]\\{\\}\\|\\.\\+\\*\\?\\(\\)\\^\\$\r\nPattern pattern = Pattern.compile(regex);<\/pre>\n<p>\u305f\u3060\u3001\u6587\u5b57\u5217\u3059\u3079\u3066\u306e\u4e2d\u304b\u3089\u6b63\u898f\u8868\u73fe\u3067\u7279\u5225\u306a\u610f\u5473\u3092\u6301\u3064\u3082\u306e\u3092\u305c\u3093\u3076\u624b\u3067\u30a8\u30b9\u30b1\u30fc\u30d7\u3059\u308b\u306e\u306f\u5927\u5909\u3067\u3059\u3002\u6f0f\u308c\u3082\u51fa\u3066\u304f\u308b\u3067\u3057\u3087\u3046\u3002\u697d\u304b\u3064\u78ba\u5b9f\u306b\u884c\u3046\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u4e8c\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><span class=\"f-marker-p\">\u65b9\u6cd5\u2460\uff1aPattern.quote(String)\u3092\u4f7f\u3046<\/span><\/strong><\/p>\n<pre class=\"prettyprint lang:default decode:true\">String regex = \"[]{}|.+*?()^$\\\\\";\r\nString regexQuoted = Pattern.quote(regex);\r\nSystem.out.println(regexQuoted); \/\/ \u2192 \\Q[]{}|.+*?()^$\\\\E\r\nPattern pattern = Pattern.compile(regexQuoted);<\/pre>\n<p>&nbsp;<\/p>\n<p><strong><span class=\"f-marker-p\">\u65b9\u6cd5\u2461\uff1a\u6b63\u898f\u8868\u73fe\u3078 \\Q \u3068 \\E \u3092\u81ea\u5206\u3067\u3064\u3051\u308b<\/span><\/strong><\/p>\n<pre class=\"prettyprint lang:default decode:true\">String regex = \"\\\\Q[]{}|.+*?()^$\\\\\\\\E\";\r\nSystem.out.println(regex); \/\/ \u2192 \\Q[]{}|.+*?()^$\\\\E\r\nPattern pattern = Pattern.compile(regex);<\/pre>\n<p>\u6b63\u898f\u8868\u73fe\u3067\u306e<span> \\Q <\/span>\u3068<span> \\E <\/span>\u306f\u3001\u3053\u306e\u4e8c\u3064\u306e\u6587\u5b57\u3067\u56f2\u307e\u308c\u3066\u3044\u308b\u6587\u5b57\u306f\u305d\u306e\u307e\u307e\u306e\u610f\u5473\u3092\u6301\u3064\u3053\u3068\u3092\u6307\u793a\u3059\u308b\u3082\u306e\u3067\u3059\u3002<span>Pattern.quote<\/span>\u306e\u7d50\u679c\u3082\u3001\u540c\u3058\u3053\u3068\u3092\u3057\u3066\u3044\u307e\u3059\u3088\u306d\u3002\u3061\u306a\u307f\u306b\u3001<span>\\Q <\/span>\u3068<span> \\E <\/span>\u306f\u9014\u4e2d\u306b\u51fa\u3066\u304d\u3066\u3082<span>OK<\/span>\u3067\u3059\u3002<\/p>\n<h3><span id=\"i-4\">\uff12-\uff13\uff0e\u6b63\u898f\u8868\u73fe\u306e\u4f8b<\/span><\/h3>\n<p>\u3053\u3053\u3067\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u73fe\u5834\u3067\u4f7f\u3048\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u6b63\u898f\u8868\u73fe\u306e\u4f8b\u3092\u3001\u3044\u304f\u3064\u304b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306b\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u6b63\u898f\u8868\u73fe\u3067\u3082\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3089\u306e\u6b63\u898f\u8868\u73fe\u306f\u3001<span>Matcher.mathces<\/span>\u3067\u30de\u30c3\u30c1\u30f3\u30b0\u78ba\u8a8d\u3092\u3059\u308b\u3053\u3068\u304c\u524d\u63d0\u3067\u3059\u3002<\/p>\n<h4>\uff12-\uff13-\uff11\uff0e\u6570\u5024\/\u91d1\u984d<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">\u30b7\u30f3\u30d7\u30eb\u306a\u6570\u5b57\u306e\u78ba\u8a8d<span>(0<\/span>\u57cb\u3081\u53ef\u3001\u6700\u5927\u6841\u6570<br \/>\n(\u4f8b\u3067\u306f<span>13<\/span>\u6841<span>)<\/span>\u3092\u660e\u793a\u3059\u308b\u5834\u5408<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">\\d{1,13}<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">\u91d1\u984d<span>(10,000<\/span>\u306a\u3069\u306e<span>3<\/span>\u6841\u533a\u5207\u308a\u3082\u53d7\u3051\u4ed8\u3051\u308b<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">-?([1-9]\\d{0,2}(,\\d{3})*|[1-9]\\d{0,})<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">\u91d1\u984d<span>(100,000.00<\/span>\u306a\u3069\u3001<span>3<\/span>\u6841\u533a\u5207\u308a\u304b\u3064\u5c0f\u6570\u70b9\u4ee5\u4e0b\u3082\u53d7\u3051\u4ed8\u3051\u308b<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000; height: 24px;\">-?([1-9]\\d{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]\\d{0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1,2})?)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff12\uff0e\u65e5\u4ed8\u30fb\u6642\u523b<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">YYYY\/MM\/DD\u30fb<span>YYYY-MM-DD<\/span>\u30fb<span>YYYY MM DD<\/span>\u306e\u3069\u308c\u304b<\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d{4}([\/\\-. ])(0?[1-9]|1[0-2])\\1(0?[1-9]|[12][0-9]|3[01])<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">YYYY\/MM\/DD\u3092\u3001\u5404\u6708\u3067\u3042\u308a\u3046\u308b\u65e5\u4ed8\u306e\u307f\u306b\u5236\u9650\u3057\u305f\u3082\u306e<\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d{4}([\/\\-. ])((0?[13578]|1[02])\\1(0?[1-9]|[12][0-9]|3[01])|0?2\\1(0?[1-9]|[12][0-9])|(0?[469]|11)\\1(0?[1-9]|[12][0-9]|30))<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u6642\u5206\u79d2(HH:MM:SS\u300124\u6642\u9593\u5236)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">(0?[1-9]|1[0-9]|2[0-3]):(0?[0-9]|[12345][0-9]):(0?[0-9]|[12345][0-9])<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u6642\u5206\u79d2(HH:MM:SS\u300112\u6642\u9593\u5236\u3001\u6700\u5f8c\u306eAM\/PM\u3067\u5224\u65ad)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">(0?[1-9]|1[0-2]):(0?[0-9]|[12345][0-9]):(0?[0-9]|[12345][0-9])(?i)(AM|PM)(?-i)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u6642\u523b\u306b\u79d2\u4ee5\u4e0b\u307e\u3067\u542b\u3080\u5834\u5408<span>(<\/span>\u30df\u30ea\u79d2\u307e\u3067\u5fc5\u9808<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">(0?[1-9]|1[0-9]|2[0-3]):(0?[0-9]|[12345][0-9]):(0?[0-9]|[12345][0-9])\\.\\d{3}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff13\uff0e\u90f5\u4fbf\u756a\u53f7(\u65e5\u672c\u56fd\u5185)<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">XXX-YYY \u304b XXXYYYY<\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d{3}-?\\d{4}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff14\uff0e\u96fb\u8a71\u756a\u53f7(\u65e5\u672c\u56fd\u5185)<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u643a\u5e2f\u96fb\u8a71<span>(IP<\/span>\u96fb\u8a71\u542b\u3080<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">0[5789]0-\\d{4}-\\d{4}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u56fa\u5b9a\u96fb\u8a71(X-Y-Z\u5f62\u5f0f)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">0(?=.{6})\\d{2,4}-\\d+-\\d{4}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u56fa\u5b9a\u96fb\u8a71(X(Y)Z\u5f62\u5f0f)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">0(?=.{6})\\d{2,4}\\(\\d+\\)\\d{4}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u5168\u3066\u6570\u5b57\u306e\u5f62\u5f0f<span>(<\/span>\u533a\u5207\u308a\u6587\u5b57\u3001<span>()<\/span>\u306a\u3057<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">0\\d{9}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u5e02\u5185\u901a\u8a71<span>(Y-Z<\/span>\u5f62\u5f0f<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d{1,4}-\\d{4}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u5e02\u5185\u901a\u8a71<span>((Y)Z<\/span>\u5f62\u5f0f<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\(\\d{1,4}\\)\\d{4}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff15\uff0e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">\u7c21\u6613\u7684\u306a\u3082\u306e<\/td>\n<td style=\"width: 50%; border-color: #000000;\">[\\w.-]+@[\\w-]+\\.[\\w.-]+<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">HTML5\u4ed5\u69d8\u306b\u3066\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u3082\u306e<\/td>\n<td style=\"width: 50%; border-color: #000000;\">[a-zA-Z0-9.!#$%&amp;&#8217;*+\\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff16\uff0eIP\u30a2\u30c9\u30ec\u30b9<\/h4>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">IPv4 \u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e<span>(256<\/span>\u3084<span>999<\/span>\u304c\u9664\u5916\u3067\u304d\u306a\u3044<span>)<\/span><\/td>\n<td style=\"width: 50%; border-color: #000000;\">(\\d{1,3}\\.){3}.\\d{1,3}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">IPv4 \u5404\u30aa\u30af\u30c6\u30c3\u30c8\u3092<span>0<\/span>\uff5e<span>255<\/span>\u307e\u3067\u3067\u30c1\u30a7\u30c3\u30af\u3067\u304d\u308b\u3082\u306e<\/td>\n<td style=\"width: 50%; border-color: #000000;\">((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">IPv6(\u53c2\u8003)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\uff12-\uff13-\uff17\uff0e\u30d0\u30fc\u30b3\u30fc\u30c9\u30fb<span>ISBN<\/span><\/h4>\n<p>\u203b\u5f62\u5f0f\u7684\u306a\u78ba\u8a8d\u306e\u307f\u3001\u30c1\u30a7\u30c3\u30af\u30b5\u30e0\u304c\u3042\u308b\u3082\u306e\u3067\u3082\u3001\u305d\u306e\u78ba\u8a8d\u307e\u3067\u306f\u884c\u308f\u306a\u3044<\/p>\n<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">JAN<\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d{8}|\\d{13}<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">CODE39(\u53ef\u5909\u9577)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">[\\dA-Z-. *$\/+%]+<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">NW-7(\u53ef\u5909\u9577)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">[\\dA-Z-.$\/+]+<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">ITF(\u53ef\u5909\u9577)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">\\d+<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">ISBN-10<\/td>\n<td style=\"width: 50%; border-color: #000000;\">ISBN(?=.{13})\\d{1,5}([- ])\\d{1,7}\\1\\d{1,6}\\1(\\d|X)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; border-color: #000000;\">ISBN-13(2019\u5e74\u6642\u70b9)<\/td>\n<td style=\"width: 50%; border-color: #000000;\">ISBN97[89]([- ])(?=.{13}$)\\d{1,5}\\1\\d{1,7}\\1\\d{1,6}\\1\\d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span id=\"Matcher\">\uff13\uff0e\u3010\u53c2\u8003\u3011Matcher\u306e\u7c21\u5358\u306a\u7d39\u4ecb<\/span><\/h2>\n<p>\u3055\u304d\u307b\u3069\u304a\u4f1d\u3048\u3057\u305f\u3068\u304a\u308a\u3001<span>Java<\/span>\u3067\u306e\u6b63\u898f\u8868\u73fe\u306f<span>Pattern<\/span>\u3060\u3051\u3067\u306f\u4f7f\u3048\u305a\u3001<span>Matcher<\/span>\u304c\u30bb\u30c3\u30c8\u306b\u306a\u308a\u307e\u3059\u3002\u3067\u3059\u306e\u3067\u3001\u3053\u3053\u3067<span>Matcher<\/span>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3082\u62bc\u3055\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3069\u306e\u3088\u3046\u306b\u6587\u5b57\u5217\u3068\u30de\u30c3\u30c1\u3055\u305b\u308b\u304b\u306f\u3001<span>Matcher<\/span>\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u5206\u3051\u307e\u3059\u3002<span>Matcher<\/span>\u306b\u306f<span>matches\/lookingAt\/find<\/span>\u3068\u3044\u3046<span>3<\/span>\u3064\u306e\u691c\u7d22\u7528\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u3001\u76ee\u7684\u306b\u5fdc\u3058\u3066\u304d\u3061\u3093\u3068\u4f7f\u3044\u5206\u3051\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001<span>Matcher.replaceAll<\/span>\u3084<span>replaceFirst<\/span>\u3082\u4fbf\u5229\u306b\u4f7f\u3048\u308b\u3082\u306e\u3067\u3059\u306e\u3067\u3001\u3053\u3053\u3067\u305d\u308c\u3089\u3082\u5c11\u3057\u7d39\u4ecb\u3057\u307e\u3059\u3002<span>Matcher<\/span>\u306e\u77e5\u8b58\u304c\u306a\u3044\u3068\u3001\u3053\u306e\u8a18\u4e8b\u306e\u5f8c\u534a\u304c\u3088\u304f\u5206\u304b\u3089\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u306b\u3082\u306a\u308a\u304b\u306d\u307e\u305b\u3093\u304b\u3089\u306d\u3002<\/p>\n<h3><span id=\"-Matchermatches\">\uff13-\uff11\uff0eMatcher.matches\u3067\u5168\u4f53\u304c\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/span><\/h3>\n<p>matches\u306f\u6587\u5b57\u5217\u5168\u4f53\u3068\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u6587\u5b57\u5217\u306e\u6700\u521d\u304b\u3089\u6700\u5f8c\u307e\u3067\u3001\u6b63\u898f\u8868\u73fe\u3068\u4e00\u81f4\u3059\u308b\u304b\u306a\u306e\u3067\u3001\u300c\u6587\u5b57\u5217\u304c\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u542b\u3093\u3067\u3044\u308b\u304b\u3060\u3051\u77e5\u308a\u305f\u3044\u300d\u3068\u3044\u3046\u30b1\u30fc\u30b9\u3067\u306f\u4f7f\u3044\u3065\u3089\u3044\u3067\u3059\u3002<\/p>\n<p>matches\u306f\u3001<span>String.equals<\/span>\u306e\u6b63\u898f\u8868\u73fe\u30d0\u30fc\u30b8\u30e7\u30f3\u3060\u3068\u601d\u3063\u3066\u3044\u305f\u3060\u3044\u3066\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"[a-z]+\"); \/\/ \u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5c0f\u6587\u5b57\u306e\u9023\u7d9a\u306b\u30de\u30c3\u30c1\u3059\u308bPattern\r\nMatcher matcher1 = pattern.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\r\nif (matcher1.matches()) {\r\n\tSystem.out.println(\"matches\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\");\r\n} else {\r\n\tSystem.out.println(\"matches\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n}\r\n\r\nMatcher matcher2 = pattern.matcher(\"abcdefg\");\r\n\r\nif (matcher2.matches()) {\r\n\tSystem.out.println(\"matches\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"matches\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}<\/pre>\n<h3><span id=\"-MatcherlookingAt\">\uff13-\uff12\uff0eMatcher.lookingAt\u3067\u5148\u982d\u304b\u3089\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/span><\/h3>\n<p>lookingAt\u306f\u6587\u5b57\u5217\u306e\u5148\u982d\u304b\u3089\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u307e\u3059\u3002\u3067\u3059\u306e\u3067\u6587\u5b57\u5217\u304c\u300c\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u304b\u3089\u59cb\u307e\u308b\u300d\u304b\u3069\u3046\u304b\u304c\u5206\u304b\u308a\u307e\u3059\u3002<span>lookingAt<\/span>\u306f\u3001<span>String.startsWith<\/span>\u306e\u6b63\u898f\u8868\u73fe\u7248\u3060\u3068\u8003\u3048\u3066\u3044\u305f\u3060\u3044\u3066\u3082\u3001\u305d\u308c\u307b\u3069\u305a\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"[a-z]+\"); \/\/ \u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5c0f\u6587\u5b57\u306e\u9023\u7d9a\u306b\u30de\u30c3\u30c1\u3059\u308bPattern\r\nMatcher matcher1 = pattern.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\r\nif (matcher1.lookingAt()) {\r\n\tSystem.out.println(\"lookingAt\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\");\r\n} else {\r\n\tSystem.out.println(\"lookingAt\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n}\r\n\r\nMatcher matcher2 = pattern.matcher(\"abcdefg \u3042\u3044\u3046\u3048\u304a\");\r\n\r\nif (matcher2.lookingAt()) {\r\n\tSystem.out.println(\"lookingAt\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"lookingAt\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}<\/pre>\n<h3><span id=\"-Matcherfind\">\uff13-\uff13\uff0eMatcher.find\u3067\u9014\u4e2d\u3067\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u308b<\/span><\/h3>\n<p>find\u306f\u6587\u5b57\u5217\u4e2d\u306b\u30d1\u30bf\u30fc\u30f3\u3092\u4e00\u3064\u3067\u3082\u542b\u3080\u304b\u3092\u5224\u65ad\u3057\u307e\u3059\u3002\u3053\u306e<span>find<\/span>\u3082\u3088\u304f\u4f7f\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u6587\u5b57\u5217\u4e2d\u306b\u30de\u30c3\u30c1\u3059\u308b\u7b87\u6240\u304c\u8907\u6570\u3042\u3063\u305f\u3068\u3057\u3066\u3082\u3001<span>find<\/span>\u3092\u8907\u6570\u56de\u5b9f\u884c\u3059\u308c\u3070\u4f55\u7b87\u6240\u306b\u30de\u30c3\u30c1\u3057\u305f\u304b\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u3059\u306e\u3067\u3001<span>find<\/span>\u306f<span>String.indexOf<\/span>\u306b\u8fd1\u3044\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002<span>String.indexOf<\/span>\u306f\u958b\u59cb\u4f4d\u7f6e\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u304c\u3001<span>find<\/span>\u3092\u8907\u6570\u56de\u7e70\u308a\u8fd4\u3059\u3068\u3044\u3046\u3053\u3068\u306f\u3001<span>indexOf<\/span>\u306e\u958b\u59cb\u4f4d\u7f6e\u3092\u5f8c\u308d\u306b\u305a\u3089\u3059\u306e\u3068\u540c\u3058\u3067\u3059\u3002\u305d\u306e\u610f\u5473\u3067\u3082\u4f3c\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"[a-z]+\"); \/\/ \u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5c0f\u6587\u5b57\u306e\u9023\u7d9a\u306b\u30de\u30c3\u30c1\u3059\u308bPattern\r\nMatcher matcher1 = pattern.matcher(\"\u3042\u3044\u3046\u3048\u304a abcdefg\");\r\n\r\nif (matcher1.find()) {\r\n\tSystem.out.println(\"find\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"find\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}\r\n\r\nMatcher matcher2 = pattern.matcher(\"abcdefg \u3042\u3044\u3046\u3048\u304a\");\r\n\r\nif (matcher2.find()) {\r\n\tSystem.out.println(\"find\u3067\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"find\u3067\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"[0-9]+\"); \/\/ \u6570\u5b57\u306e\u9023\u7d9a\u306b\u30de\u30c3\u30c1\u3059\u308bPattern\r\nMatcher matcher = pattern.matcher(\"123 456\");\r\n\r\n\/\/ 1\u56de\u76ee\u306efind\u306f 123 \u306b\u30de\u30c3\u30c1\u3059\u308b\r\nif (matcher.find()) {\r\n\tSystem.out.println(\"1\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"1\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}\r\n\r\n\/\/ 2\u56de\u76ee\u306efind\u306f 456 \u306b\u30de\u30c3\u30c1\u3059\u308b\r\nif (matcher.find()) {\r\n\tSystem.out.println(\"2\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n} else {\r\n\tSystem.out.println(\"2\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}\r\n\r\n\/\/ 3\u56de\u76ee\u306efind\u306f\u3082\u3046\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u306a\u3044\u306e\u3067false\u306b\u306a\u308b\r\nif (matcher.find()) {\r\n\tSystem.out.println(\"3\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\");\r\n} else {\r\n\tSystem.out.println(\"3\u56de\u76ee\u306efind\u306f\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n}<\/pre>\n<h3><span id=\"-MatcherreplaceAllreplaceFirst\">\uff13-\uff14\uff0eMatcher.replaceAll\/replaceFirst\u3067\u4e00\u81f4\u90e8\u5206\u3092\u5165\u308c\u66ff\u3048\u308b<\/span><\/h3>\n<p>Matcher.replaceAll\u3068replaceFirst\u306f\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u5165\u308c\u66ff\u3048\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002String.replaceAll\u3068<span>String.replaceFirst<\/span>\u306e\u4e2d\u3067\u884c\u308f\u308c\u3066\u3044\u308b\u51e6\u7406\u305d\u306e\u3082\u306e\u3067\u3082\u3042\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Java 11\u306e\u65e5\u672c\u8a9e\u7248Javadoc\u3088\u308a\u629c\u7c8b\r\npublic String replaceAll(String replacement)\r\n\t\u30d1\u30bf\u30fc\u30f3\u3068\u30de\u30c3\u30c1\u3059\u308b\u5165\u529b\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u3001\u6307\u5b9a\u3055\u308c\u305f\u7f6e\u63db\u6587\u5b57\u5217\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002\r\n\u30d1\u30e9\u30e1\u30fc\u30bf:\r\n\treplacement - \u7f6e\u63db\u6587\u5b57\u5217\r\n\u623b\u308a\u5024:\r\n\t\u30de\u30c3\u30c1\u3057\u305f\u3059\u3079\u3066\u306e\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u7f6e\u63db\u6587\u5b57\u5217\u3067\u7f6e\u304d\u63db\u3048\u3001\u524d\u65b9\u53c2\u7167\u3055\u308c\u305f\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u7f6e\u63db\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u69cb\u7bc9\u3055\u308c\u305f\u6587\u5b57\u5217<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ Java 11\u306e\u65e5\u672c\u8a9e\u7248Javadoc\u3088\u308a\u629c\u7c8b\r\npublic String replaceFirst(String replacement)\r\n\t\u30d1\u30bf\u30fc\u30f3\u3068\u30de\u30c3\u30c1\u3059\u308b\u5165\u529b\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u3046\u3061\u3001\u6700\u521d\u306e\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u6307\u5b9a\u3055\u308c\u305f\u7f6e\u63db\u6587\u5b57\u5217\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002\r\n\u30d1\u30e9\u30e1\u30fc\u30bf:\r\n\treplacement - \u7f6e\u63db\u6587\u5b57\u5217\r\n\u623b\u308a\u5024:\r\n\t\u6700\u521d\u306b\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u7f6e\u63db\u6587\u5b57\u5217\u3067\u7f6e\u304d\u63db\u3048\u3001\u524d\u65b9\u53c2\u7167\u3055\u308c\u305f\u90e8\u5206\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u7f6e\u63db\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u69cb\u7bc9\u3055\u308c\u305f\u6587\u5b57\u5217<\/pre>\n<p>\u4f7f\u3044\u65b9\u3060\u3051\u7c21\u5358\u306b\u304a\u4f1d\u3048\u3057\u3066\u304a\u304d\u307e\u3059\u3002<span>replaceAll<\/span>\u306f\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3059\u3079\u3066\u3092\u5165\u308c\u66ff\u3048\u3066\u3001<span>replaceFirst<\/span>\u306f\u6700\u521d\u306b\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u306e\u307f\u5165\u308c\u66ff\u3048\u307e\u3059\u3002\u3053\u306e\u4e8c\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u3082\u3046\u5c11\u3057\u4fbf\u5229\u306a\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"[a-z]+\");\r\n\r\nMatcher matcher1 = pattern.matcher(\"abcd efgh\");\r\nString replaced1 = matcher1.replaceAll(\"1234\");\r\nSystem.out.println(replaced1); \/\/ \u2192 1234 1234\u3001\u82f1\u8a9e\u90e8\u5206\u304c\u5168\u30661234\u306b\u306a\u3063\u305f\r\n\r\nMatcher matcher2 = pattern.matcher(\"abcd efgh\");\r\nString replaced2 = matcher2.replaceFirst(\"1234\");\r\nSystem.out.println(replaced2); \/\/ \u2192 1234 efgh\u3001\u82f1\u8a9e\u90e8\u5206\u306e\u6700\u521d\u3060\u30511234\u306b\u306a\u3063\u305f<\/pre>\n<h3><span id=\"-Matchergroupgroups\">\uff13-\uff15\uff0eMatcher.group\/groups\u3067\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u7d50\u679c\u3092\u53d6\u308a\u51fa\u3059<\/span><\/h3>\n<p>Matcher\u306e\u3068\u3066\u3082\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u306f\u3001<span>group\/groups<\/span>\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u6b63\u898f\u8868\u73fe\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc<span>(capture)<\/span>\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u3092\u4f7f\u3046\u305f\u3081\u306b\u3042\u308a\u3001<span>Pattern<\/span>\u3068\u306e\u3064\u306a\u304c\u308a\u304c\u3068\u3066\u3082\u5f37\u3044\u306e\u3067\u3001\u5f8c\u3067\u8a73\u3057\u304f\u304a\u4f1d\u3048\u3057\u307e\u3059\u3002<\/p>\n<h2><span id=\"i-5\">\uff14\uff0e\u6b63\u898f\u8868\u73fe\u306e\u6d3b\u7528\u4f8b<\/span><\/h2>\n<p>\u3053\u3053\u3067\u306f\u3001\u6b63\u898f\u8868\u73fe\u306e\u6d3b\u7528\u4f8b\u3092\u3044\u304f\u3064\u304b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001<span>Java<\/span>\u3067\u306f<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u3092\u76f4\u63a5\u4f7f\u3046\u4ee5\u5916\u306b\u3082\u3001<span>String<\/span>\u306a\u3069\u306b\u306f\u6b63\u898f\u8868\u73fe\u304c\u6307\u5b9a\u3067\u304d\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u3089\u3092\u4fbf\u5229\u306b\u4f7f\u3046\u3053\u3068\u304c\u3001<span>Java<\/span>\u3067\u306e\u6b63\u898f\u8868\u73fe\u3092\u6d3b\u7528\u3059\u308b\u305f\u3081\u306e\u30b3\u30c4\u3060\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u3059\u3002<\/p>\n<h3><span id=\"i-6\">\uff14-\uff11\uff0e\u7a7a\u767d\u3084\u533a\u5207\u308a\u6587\u5b57\u306a\u3069\u306e\u9664\u53bb\u3001\u7f6e\u63db<\/span><\/h3>\n<p>\u7a7a\u767d\u3084\u533a\u5207\u308a\u6587\u5b57\u306e\u9664\u53bb\u3084\u7f6e\u63db\u306f\u3001\u6b63\u898f\u8868\u73fe\u306e\u72ec\u58c7\u5834\u3067\u3059\u3002\u4ee5\u4e0b\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u9014\u4e2d\u306e\u7a7a\u767d\u3092\u3059\u3079\u3066\u9664\u53bb\u3059\u308b\u3082\u306e\u3067\u3059\u3002\u7f6e\u63db\u5148\u3092<span>&#8220;&#8221;<\/span>\u306b\u3059\u308c\u3070\u3001\u6587\u5b57\u306e\u524a\u9664\u3068\u540c\u3058\u52b9\u679c\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A B C D\";\r\nPattern p = Pattern.compile(\" \");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"\");\r\nSystem.out.println(r); \/\/ \u2192 ABCD<\/pre>\n<p>Pattern\u3068Matcher.replaceAll\u3092\u4f7f\u3046\u4ee3\u308f\u308a\u306b\u3001String.replaceAll\u3067\u3082\u540c\u3058\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002String.replaceAll\u306f\u5185\u90e8\u7684\u306b<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u7d50\u679c\u306f\u540c\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A B C D\";\r\nString r = s.replaceAll(\" \", \"\");\r\nSystem.out.println(r); \/\/ \u2192 ABCD<\/pre>\n<p>\u6b63\u898f\u8868\u73fe\u3067\u3059\u304b\u3089\u3001\u7a7a\u767d\u3060\u3051\u3067\u306a\u304f\u3001\u3044\u304f\u3064\u304b\u306e\u6587\u5b57\u3092\u7f6e\u63db\u5bfe\u8c61\u3068\u3057\u3066\u540c\u6642\u306b\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u4f8b\u3067\u306f\u3001\u7a7a\u767d\u3068\u30bf\u30d6\u3068\u6539\u884c\u6587\u5b57\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u3069\u308c\u304b\u306b\u8a72\u5f53\u3059\u308c\u3070<span>OK<\/span>\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A B\\tC\\nD\"; \/\/ \u30bf\u30d6(\\t)\u3068\u6539\u884c(\\n)\u3092\u542b\u3080\r\nPattern p = Pattern.compile(\"[ \\t\\n]\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"\");\r\nSystem.out.println(r); \/\/ \u2192 ABCD<\/pre>\n<p>\u6587\u5b57\u5217\u306e\u5148\u982d\u3042\u308b\u3044\u306f\u672b\u5c3e\u306e\u7a7a\u767d\u6587\u5b57\u3092\u524a\u9664\u3059\u308b\u3053\u3068\u3082\u7c21\u5358\u3067\u3059\u3002<span>String.trim<\/span>\u3067\u306f\u3044\u308f\u3086\u308b\u5168\u89d2\u7a7a\u767d\u3092\u524a\u9664\u3057\u3066\u304f\u308c\u307e\u305b\u3093\u3057\u3001\u5148\u982d\u3060\u3051\u30fb\u672b\u5c3e\u3060\u3051\u306e\u524a\u9664\u3082\u3067\u304d\u307e\u305b\u3093\u3002\u3067\u3059\u304c\u3001\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3048\u3070\u7c21\u5358\u306b\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \" \u3000 A B C D \u3000 \"; \/\/ \u2190\u5148\u982d\u30fb\u672b\u5c3e\u306b\u5168\u89d2\u534a\u89d2\u7a7a\u767d\u304c\u6df7\u5728\u3057\u3066\u3044\u307e\u3059\r\n\r\nPattern p1 = Pattern.compile(\"^[\\\\s\u3000]+\");\r\nMatcher m1 = p1.matcher(s);\r\nString r1 = m1.replaceFirst(\"\");\r\n\r\nPattern p2 = Pattern.compile(\"[\\\\s\u3000]+$\");\r\nMatcher m2 = p2.matcher(r1);\r\nString r2 = m2.replaceFirst(\"\");\r\n\r\nSystem.out.println(r2); \/\/ \u2192 \"A B C D\"<\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001<span>String.replaceFirst<\/span>\u3067\u3084\u3063\u3066\u3082\u540c\u3058\u7d50\u679c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \" \u3000 A B C D \u3000 \"; \/\/ \u2190\u5148\u982d\u30fb\u672b\u5c3e\u306b\u5168\u89d2\u534a\u89d2\u7a7a\u767d\u304c\u6df7\u5728\u3057\u3066\u3044\u307e\u3059\r\nString r = str.replaceFirst(\"^[\\\\s\u3000]+\", \"\").replaceFirst(\"[\\\\s\u3000]+$\", \"\");\r\nSystem.out.println(r); \/\/ \u2192 \"A B C D\"<\/pre>\n<p>\\s \u3068\u306f\u5225\u306e\u3001\u7a7a\u767d\u6587\u5b57\u3092\u8868\u3059\u6587\u5b57\u30af\u30e9\u30b9<span> \\h <\/span>\u3092\u4f7f\u3063\u3066\u3082\u3044\u3044\u3067\u3057\u3087\u3046\u3002\u3053\u3061\u3089\u306b\u306f\u5168\u89d2\u7a7a\u767d\u3082\u542b\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \" \u3000 A B C D \u3000 \"; \/\/ \u2190\u5148\u982d\u30fb\u672b\u5c3e\u306b\u5168\u89d2\u534a\u89d2\u7a7a\u767d\u304c\u6df7\u5728\u3057\u3066\u3044\u307e\u3059\r\n\r\nPattern p1 = Pattern.compile(\"^\\\\h+\");\r\nMatcher m1 = p1.matcher(s);\r\nString r1 = m1.replaceFirst(\"\");\r\n\r\nPattern p2 = Pattern.compile(\"\\\\h+$\");\r\nMatcher m2 = p2.matcher(r1);\r\nString r2 = m2.replaceFirst(\"\");\r\n\r\nSystem.out.println(r2); \/\/ \u2192 \"A B C D\"<\/pre>\n<p>String.replaceFirst\u3067\u3084\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \" \u3000 A B C D \u3000 \"; \/\/ \u2190\u5148\u982d\u30fb\u672b\u5c3e\u306b\u5168\u89d2\u534a\u89d2\u7a7a\u767d\u304c\u6df7\u5728\u3057\u3066\u3044\u307e\u3059\r\nString r = s.replaceFirst(\"^\\\\h+\", \"\").replaceFirst(\"\\\\h+$\", \"\");\r\nSystem.out.println(r); \/\/ \u2192 \"A B C D\"<\/pre>\n<p>\u3053\u308c\u4ee5\u5916\u306b\u3082\u3001\u6587\u5b57\u5217\u304b\u3089\u306e<span>trim<\/span>\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3082\u3042\u308a\u307e\u3059\u3002\u3044\u308d\u3044\u308d\u306a<span>trim<\/span>\u306e\u4ed5\u65b9\u306b\u3064\u3044\u3066\u66f8\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u3088\u308d\u3057\u3051\u308c\u3070\u3054\u89a7\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n<span style=\"text-decoration:none !important; background-color:#a61e58; color:white; padding:4px 13px; font-size:12px; font-weight:bold; position:relative; top:10px; z-index:1; left:11px;\">\u95a2\u9023\u8a18\u4e8b<\/span>\n<div class=\"blog-card\"><a target=\"_blank\" href=\"https:\/\/www.bold.ne.jp\/engineer-club\/java-trim\" style=\"text-decoration:none;\">\n    <div class=\"blog-card-thumbnail\"><img src='https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2018\/10\/shutterstock_568617811-600x366.jpg' alt='Java\u306etrim\u3068\u306f\uff1f\u534a\u89d2\u30fb\u5168\u89d2\u7a7a\u767d\u3092\u524a\u9664\u3059\u308b\u305f\u3081\u306etrim\u306e\u4f7f\u3044\u65b9' width=160 height=98 \/><\/div>\n    <div class=\"blog-card-content\">\n        <div class=\"blog-card-title\">Java\u306etrim\u3068\u306f\uff1f\u534a\u89d2\u30fb\u5168\u89d2\u7a7a\u767d\u3092\u524a\u9664\u3059\u308b\u305f\u3081\u306etrim\u306e\u4f7f\u3044\u65b9 <\/div>\n        <span style=\"font-size: 12px; font-weight: normal; position:relative; color:#666;\"><i class=\"fa fa-clock-o\"><\/i>&nbsp;2025\/10\/06<\/span>\n    <\/div>\n<div class=\"clear\"><\/div>\n<\/a><\/div>\n<h3><span id=\"i-7\">\uff14-\uff12\uff0e\u6587\u5b57\u5217\u306e\u8981\u7d20\u5206\u89e3<span>(<\/span>\u7a7a\u767d\u30fb\u30ab\u30f3\u30de\u533a\u5207\u308a\u306a\u3069<span>)<\/span><\/span><\/h3>\n<p>\u5148\u307b\u3069\u306f\u533a\u5207\u308a\u6587\u5b57\u306e\u7f6e\u63db\u306a\u3069\u3092\u884c\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u5ea6\u306f\u5206\u5272\u3067\u3059\u3002\u6587\u5b57\u5217\u306e\u5206\u5272\u306f<span>String.split<\/span>\u3092\u4f7f\u3046\u306e\u304c\u666e\u901a\u3060\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u5b9f\u306f\u5185\u90e8\u7684\u306b\u306f<span>Pattern<\/span>\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u3067\u3059\u304b\u3089\u3001\u3053\u306e\u3088\u3046\u306b\u3082\u66f8\u3051\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"KEY=VALUE1,VALUE2,VALUE3\";\r\nPattern p = Pattern.compile(\"[=,]\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [KEY, VALUE1, VALUE2, VALUE3]\r\nSystem.out.println(split.length); \/\/ \u2192 4<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A    B  C        D\";\r\nPattern p = Pattern.compile(\" +\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [A, B, C, D]\r\nSystem.out.println(split.length); \/\/ \u2192 4<\/pre>\n<p>\u6b63\u898f\u8868\u73fe\u3092\u7a7a\u6587\u5b57\u5217\u306b\u3059\u308b\u3068\u3001\u6587\u5b57\u306e\u5883\u754c\u306b\u30de\u30c3\u30c1\u3059\u308b\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002\u3067\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3084\u308b\u3068\u6587\u5b57\u5358\u4f4d\u306b\u5206\u5272\u3067\u304d\u308b\u306e\u3067\u3059\u306d\u3002\u5c11\u3057\u88cf\u6280\u30c1\u30c3\u30af\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"ABCDEF\";\r\nPattern p = Pattern.compile(\"\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [A, B, C, D, E, F]\r\nSystem.out.println(split.length); \/\/ \u2192 6<\/pre>\n<p>\u6b63\u898f\u8868\u73fe\u306f\u6539\u884c\u6587\u5b57\u3082\u6307\u5b9a\u3067\u304d\u308b\u306e\u3067\u3001\u8907\u6570\u884c\u3092\u542b\u3093\u3060\u6587\u5b57\u5217\u3082\u884c\u3054\u3068\u306b\u5206\u89e3\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A\\nBC\\r\\n\\rD\";\r\nPattern p = Pattern.compile(\"\\r\\n|\\r|\\n\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [A, BC, \"\", D]\r\nSystem.out.println(split.length); \/\/ \u2192 4<\/pre>\n<p>\u533a\u5207\u308a\u6587\u5b57\u305d\u306e\u3082\u306e\u3082\u3001\u5206\u5272\u3057\u305f\u5f8c\u306e\u6587\u5b57\u5217\u306b\u542b\u3081\u305f\u3044<span>? <\/span>\u305d\u308c\u306a\u3089\u3001\u5c11\u3057\u7279\u6b8a\u306a\u66f8\u304d\u65b9\u3092\u3059\u308c\u3070\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u306f\u3001\u5f8c\u8ff0\u3059\u308b\u80af\u5b9a\u5f8c\u8aad\u307f\u3068\u3001\u80af\u5b9a\u5148\u8aad\u307f\u3068\u3044\u3046\u6b63\u898f\u8868\u73fe\u306e\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A,BC,,D\";\r\nPattern p = Pattern.compile(\"(?&lt;=,)\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [\"A,\", \"BC,\", \",\", \"D\"]\r\nSystem.out.println(split.length); \/\/ \u2192 4<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A,BC,,D\";\r\nPattern p = Pattern.compile(\"(?=,)\");\r\nString[] split = p.split(s);\r\nSystem.out.println(java.util.Arrays.toString(split)); \/\/ \u2192 [\"A\", \",BC\", \",\", \",D\"]\r\nSystem.out.println(split.length); \/\/ \u2192 4<\/pre>\n<h3><span id=\"i-8\">\uff14-\uff13\uff0e\u6587\u5b57\u5217\u306e\u30de\u30b9\u30af<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306f\u3001\u4f8b\u3048\u3070\u3001\u4f55\u304b\u306e\u6587\u5b57\u5217\u3092\u30de\u30b9\u30af\u3059\u308b\u306e\u306b\u3082\u4f7f\u3048\u305f\u308a\u3057\u307e\u3059\u3002<span>Matcher.replaceAll<\/span>\u306e\u6d3b\u7528\u4f8b\u306e\u4e00\u3064\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"The quick brown fox jumps over the lazy dog\";\r\nPattern p = Pattern.compile(\"fox|dog\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"xxx\");\r\nSystem.out.println(r); \/\/ \u2192 The quick brown xxx jumps over the lazy xxx<\/pre>\n<p>\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u7121\u8996\u3057\u305f\u3051\u308c\u3070\u3001\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u7121\u8996\u3059\u308b\u57cb\u3081\u8fbc\u307f\u30d5\u30e9\u30b0<span> (?i) <\/span>\u3092\u4f7f\u3046\u306e\u304c\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"The quick brown FoX jumps over the lazy dOg\";\r\nPattern p = Pattern.compile(\"(?i)fox|dog\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"xxx\");\r\nSystem.out.println(r); \/\/ \u2192 The quick brown xxx jumps over the lazy xxx<\/pre>\n<h3><span id=\"i-9\">\uff14-\uff14\uff0e\u533a\u5207\u308a\u6587\u5b57\u306e\u7d71\u4e00<\/span><\/h3>\n<p>\u6587\u5b57\u5217\u7f6e\u63db\u306e\u30d0\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u306e\u4e00\u3064\u3067\u3059\u304c\u3001\u8907\u6570\u306e\u533a\u5207\u308a\u6587\u5b57\u304c\u6df7\u5728\u3057\u305f\u6587\u5b57\u5217\u306e\u533a\u5207\u308a\u6587\u5b57\u3092\u3001\u4f55\u304b\u306b\u7d71\u4e00\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A\\r\\nB\\rC\\nD\";\r\nPattern p = Pattern.compile(\"\\\\r\\\\n|\\\\r|\\\\n\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"\\r\\n\");\r\nSystem.out.println(r); \/\/ \u2192 \"A\\r\\nB\\r\\nC\\r\\nD\"\r\nSystem.out.println(java.util.Arrays.toString(r.getBytes())); \/\/ \u2192 [65, 13, 10, 66, 13, 10, 67, 13, 10, 68]<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"A,B\\tC-D\";\r\nPattern p = Pattern.compile(\"[,\\t-]\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\",\");\r\nSystem.out.println(r); \/\/ \u2192 A,B,C,D<\/pre>\n<h3><span id=\"i-10\">\uff14-\uff15\uff0e\u97f3\u5f15\u304d\u306e\u7d71\u4e00<\/span><\/h3>\n<p>\u3042\u307e\u308a\u898b\u306a\u3044\u4f8b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u5fae\u5999\u306b\u9055\u3046\u97f3\u5f15\u304d<span>(&#8220;<\/span>\u30fc<span>&#8220;)<\/span>\u3092\u4e00\u767a\u3067\u7d71\u4e00\u3067\u304d\u305f\u308a\u3082\u3057\u307e\u3059\u3002\u3053\u3093\u306a\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u304b\u306a<span>? <\/span>\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u6b63\u898f\u8868\u73fe\u3067\u306f\u5b9f\u306f\u3067\u304d\u3066\u3057\u307e\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u3068\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306f\u540c\u3058\u3082\u306e?\";\r\n\r\nPattern p1 = Pattern.compile(\"(\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf)([\u30fc])\");\r\nMatcher m1 = p1.matcher(s);\r\nString r1 = m1.replaceAll(\"$1\");\r\nSystem.out.println(r1); \/\/ \u2192 \u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u3068\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306f\u540c\u3058\u3082\u306e?\r\n\r\nPattern p2 = Pattern.compile(\"(\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf)([^\u30fc])\");\r\nMatcher m2 = p2.matcher(s);\r\nString r2 = m2.replaceAll(\"$1\u30fc$2\");\r\nSystem.out.println(r2); \/\/ \u2192 \u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u3068\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u306f\u540c\u3058\u3082\u306e?<\/pre>\n<h3><span id=\"-HTMLXML\">\uff14-\uff16\uff0eHTML\/XML\u4e2d\u306e\u5c5e\u6027\u5024\u306e\u524a\u9664<\/span><\/h3>\n<p>\u30d1\u30bf\u30fc\u30f3\u304c\u898b\u3064\u3051\u3089\u308c\u3055\u3048\u3059\u308c\u3070\u3001\u5bfe\u8c61\u304c<span>HTML<\/span>\u3084<span>XML<\/span>\u3067\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u30bf\u30b0\u306b\u3042\u308b\u4e0d\u8981\u306a\u5c5e\u6027\u5024<span>(height)<\/span>\u306b\u3064\u3044\u3066\u3001\u5c5e\u6027\u540d\u3068\u5024\u306e\u4e21\u65b9\u3092\u524a\u9664\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"&lt;img height=\\\"100\\\" class=\\\"main\\\" \/&gt;&lt;img height=\\\"50\\\" class=\\\"footer\\\" \/&gt;\";\r\nPattern p = Pattern.compile(\" height=\\\"[^\\\"]+?\\\"\");\r\nMatcher m = p.matcher(s);\r\nString r = m.replaceAll(\"\");\r\nSystem.out.println(r); \/\/ \u2192 &lt;img class=\"main\" \/&gt;&lt;img class=\"footer\" \/&gt;<\/pre>\n<h3><span id=\"i-11\">\uff14-\uff17\uff0e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u89e3\u6790<\/span><\/h3>\n<p>\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306f\u6c7a\u307e\u3063\u305f\u5f62\u5f0f\u3067\u3042\u308b\u3053\u3068\u304c\u591a\u3044\u3082\u306e\u3067\u3059\u3002\u3088\u304f\u898b\u308b\u5f62\u5f0f\u306f\u3001\u65e5\u6642\u3001\u30ed\u30b0\u30ec\u30d9\u30eb\u3001\u30ed\u30b0\u51fa\u529b\u30af\u30e9\u30b9\u3001\u30ed\u30b0\u30e1\u30c3\u30bb\u30fc\u30b8\u304c<span>1<\/span>\u884c\u306b\u307e\u3068\u307e\u3063\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u3093\u306a\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e<span>1<\/span>\u884c\u304b\u3089\u3001\u305d\u308c\u305e\u308c\u306e\u60c5\u5831\u3092\u629c\u304d\u53d6\u308b\u306e\u306b\u3082\u3001\u6b63\u898f\u8868\u73fe\u306f\u4fbf\u5229\u306b\u4f7f\u3048\u307e\u3059\u3002\u3053\u306e\u4f8b\u3067\u306f\u3001\u5f8c\u8ff0\u3059\u308b\u6b63\u898f\u8868\u73fe\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<span>String.split<\/span>\u3092\u4f7f\u3063\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u5c11\u3005\u9762\u5012\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">String s = \"2019-05-25 12:34:56.789 INFO - [jp.engineer_club.pattern.Test] Message from program!!\";\r\nPattern p = Pattern.compile(\"^(\\\\d{4}-\\\\d{2}-\\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2}\\\\.\\\\d{3}) ([A-Z]+) +- \\\\[([\\\\w.]+)\\\\] (.+)$\");\r\nMatcher m = p.matcher(s);\r\nm.matches();\r\nSystem.out.println(m.group(1)); \/\/ \u2192 2019-05-25 12:34:56.789\r\nSystem.out.println(m.group(2)); \/\/ \u2192 INFO\r\nSystem.out.println(m.group(3)); \/\/ \u2192 jp.engineer_club.pattern.Test\r\nSystem.out.println(m.group(4)); \/\/ \u2192 Message from program!!<\/pre>\n<h3><span id=\"i-12\">\uff14-\uff18\uff0e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u6587\u5b57\u5217\u7f6e\u63db<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u3067\u30de\u30c3\u30c1\u30f3\u30b0\u3055\u305b\u305f\u6587\u5b57\u5217\u3092\u3001\u4f55\u304b\u306e\u30eb\u30fc\u30eb\u3067\u6c7a\u3081\u305f\u6587\u5b57\u5217\u3067\u7f6e\u63db\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u3001\u6b63\u898f\u8868\u73fe\u3067\u30de\u30c3\u30c1\u30f3\u30b0\u3055\u305b\u305f\u6587\u5b57\u5217\u306b\u5bfe\u5fdc\u3059\u308b\u6587\u5b57\u5217\u3092<span>Map<\/span>\u304b\u3089\u63a2\u3057\u3066\u3001\u7f6e\u63db\u3059\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u3054\u304f\u7c21\u5358\u306a\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u306d\u3002<span>String.replace<\/span>\u3067\u3082\u540c\u3058\u3053\u3068\u306f\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u3046\u3044\u3046\u3084\u308a\u65b9\u3082\u3001\u3084\u308d\u3046\u3068\u3059\u308c\u3070\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Map&lt;String, String&gt; param = new HashMap&lt;&gt;();\r\nparam.put(\"aaaa\", \"\u3042\u3044\u3046\u3048\u304a\");\r\nparam.put(\"bbbb\", \"\u304b\u304d\u304f\u3051\u3053\");\r\nparam.put(\"cccc\", \"\u3055\u3057\u3059\u305b\u305d\");\r\nparam.put(\"dddd\", \"\u305f\u3061\u3064\u3066\u3068\");\r\n\r\nString s = \"{aaaa} {bbbb} {cccc} {dddd}\";\r\nString s2 = null;\r\nPattern p = Pattern.compile(\"(\\\\{(\\\\w+?)\\\\})\");\r\nMatcher m = p.matcher(s);\r\n\r\nwhile (m.find()) {\r\n\tString key = m.group(2);\r\n\ts2 = m.replaceFirst(param.get(key));\r\n\tm.reset(s2);\r\n}\r\n\r\nSystem.out.println(s2); \/\/ \u2192 \u3042\u3044\u3046\u3048\u304a \u304b\u304d\u304f\u3051\u3053 \u3055\u3057\u3059\u305b\u305d \u305f\u3061\u3064\u3066\u3068<\/pre>\n<h2><span id=\"Pattern\">\uff15\uff0e\u3010\u767a\u5c55\u3011<span>Pattern<\/span>\u306e\u4fbf\u5229\u306a\u6a5f\u80fd\u305f\u3061<\/span><\/h2>\n<p>\u3055\u3066\u3001\u3053\u3053\u307e\u3067\u304c<span>Java<\/span>\u306e\u30af\u30e9\u30b9\u3068\u3057\u3066\u306e<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u306e\u57fa\u672c\u3067\u3059\u3002\u3053\u3053\u304b\u3089\u306f\u3001<span>Pattern<\/span>\u3068<span>Matcher<\/span>\u3092<span>256%<\/span>\u6d3b\u7528\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u77e5\u8b58\u3084\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4ed5\u65b9\u3092\u304a\u4f1d\u3048\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3><span id=\"i-13\">\uff15-\uff11\uff0e\u3010\u91cd\u8981\u3011\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u53d6\u308a\u51fa\u3059\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc<\/span><\/h3>\n<p>Pattern\u306e\u6a5f\u80fd\u3067\u7d76\u5bfe\u306b\u4f7f\u3044\u305f\u3044\u306e\u304c\u3001<span>&#8220;()&#8221;<\/span>\u3092\u4f7f\u3063\u305f\u30b0\u30eb\u30fc\u30d7\u5316\u3068\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u306e\u53c2\u7167\u3067\u3059\u3002\u6b63\u898f\u8868\u73fe\u306e\u4e16\u754c\u3067\u306f\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc<span>(capture)<\/span>\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u77e5\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3067\u4f5c\u696d\u52b9\u7387\u306f\u5927\u9055\u3044\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u6b63\u898f\u8868\u73fe\u306f\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u3059\u308b\u304b\u78ba\u8a8d\u3059\u308b\u3060\u3051\u306e\u3082\u306e\u3067\u306f\u306a\u3044\u306e\u3067\u3059<span>!! <\/span>\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3059\u308c\u3070\u3001\u5f8c\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3067\u304d\u305f\u308a\u3001\u7f6e\u63db\u306a\u3069\u306b\u6d3b\u7528\u3067\u304d\u308b\u3053\u3068\u306f\u305c\u3072\u77e5\u3063\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>\uff15-\uff11-\uff11\uff0eMatcher.group(int)\u3092\u4f7f\u3063\u3066\u307f\u308b<\/h4>\n<p>Matcher.group\u3092\u4f7f\u3046\u3068\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u5f8c\u304b\u3089\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u6587\u5b57\u5217\u306e\u30de\u30c3\u30c1\u30f3\u30b0\u3068\u62bd\u51fa\u3092\u4e00\u5ea6\u306b\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u304c\u3067\u304d\u308c\u3070\u3001\u9762\u5012\u306a<span>String.substring<\/span>\u3084<span>indexOf<\/span>\u3068\u306f\u3082\u3046\u304a\u3055\u3089\u3070\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(\\\\d{4})\/(\\\\d{2})\/(\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\");\r\n\r\nif (matcher.find()) {\r\n\tString ymd = matcher.group(0);\r\n\tSystem.out.println(ymd); \/\/ \u2192 2019\/04\/30\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u5168\u4f53\u306e\u6587\u5b57\u5217\r\n\r\n\tString yyyy = matcher.group(1); \/\/ \u2192 2019\u30011\u756a\u76ee\u306e()\u306e\u4e2d\u306e\u6587\u5b57\u5217\r\n\tString mm = matcher.group(2); \/\/ \u2192 04\u30012\u756a\u76ee\u306e()\u306e\u4e2d\u306e\u6587\u5b57\u5217\r\n\tString dd = matcher.group(3); \/\/ \u2192 30\u30012\u756a\u76ee\u306e()\u306e\u4e2d\u306e\u6587\u5b57\u5217\r\n\tSystem.out.println(yyyy + mm + dd); \/\/ \u2192 20190430\r\n}<\/pre>\n<p>group\u3078\u306e\u6570\u5b57\u306f\u3001\u30d1\u30bf\u30fc\u30f3\u4e2d\u306b\u3042\u308b<span>()<\/span>\u306e<span>1<\/span>\u304b\u3089\u306e\u9023\u756a\u3067\u3059\u3002<span>0<\/span>\u3060\u3068\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u306e\u5168\u4f53\u304c\u623b\u308a\u307e\u3059\u3002\u3069\u308c\u3060\u3051\u30de\u30c3\u30c1\u3057\u305f\u7b87\u6240\u304c\u3042\u308b\u304b\u306f\u3001<span>Matcher.groupCount<\/span>\u3067\u5206\u304b\u308a\u307e\u3059\u3002\u3053\u306e\u4f8b\u3067\u306f\u3001<span>groupCount<\/span>\u306f<span>3<\/span>\u304c\u623b\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(\\\\d{4})\/(\\\\d{2})\/(\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\");\r\n\r\nif (matcher.find()) {\r\n\tfor (int i = 0; i &lt;= matcher.groupCount(); i++) {\r\n\t\tSystem.out.println(matcher.group(i)); \/\/ 0:2019\/04\/30\u30011:2019\u30012:04\u30013:30\r\n\t}\r\n}<\/pre>\n<p>\u3082\u3057\u4e00\u3064\u306e\u6587\u5b57\u5217\u306b\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u8907\u6570\u3042\u308b\u306e\u306a\u3089\u3001<span>find<\/span>\u304c<span>false<\/span>\u3092\u623b\u3059\u307e\u3067\u30eb\u30fc\u30d7\u3092\u3057\u307e\u3057\u3087\u3046\u3002<span>find<\/span>\u306f\u4e00\u3064\u306e\u6587\u5b57\u5217\u306e\u4e2d\u306b\u8907\u6570\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308b\u306a\u3089\u3001\u8907\u6570\u56de\u5b9f\u884c\u3059\u308b\u3068\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u3092\u5168\u90e8\u8abf\u3079\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(\\\\d{4})\/(\\\\d{2})\/(\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u30022019\/05\/01\u304b\u3089\u4ee4\u548c\u306b\u306a\u308a\u307e\u3059\u3002\");\r\n\r\n\/\/ find\u304cfalse\u3092\u623b\u3059\u307e\u3067while\u6587\u3067\u30eb\u30fc\u30d7\u3059\u308b\r\n\/\/ find\u3067\u898b\u3064\u304b\u3063\u305f\u5358\u4f4d\u3067group\u304c\u3067\u304d\u308b\r\nwhile (matcher.find()) {\r\n\tString ymd = matcher.group(0);\r\n\tSystem.out.println(ymd); \/\/ \u2192 2019\/04\/30\u30012019\/05\/01\r\n\r\n\tString yyyy = matcher.group(1);\r\n\tString mm = matcher.group(2);\r\n\tString dd = matcher.group(3);\r\n\tSystem.out.println(yyyy + mm + dd); \/\/ \u2192 20190430\u300120190501\r\n}<\/pre>\n<h4>\uff15-\uff11-\uff12\uff0eMatcher.group(String)\u3092\u4f7f\u3063\u3066\u307f\u308b<\/h4>\n<p>Matcher.group(int)\u3067\u306f\u4f4d\u7f6e\u3092\u6570\u5b57\u3067\u6307\u5b9a\u3057\u307e\u3057\u305f\u304c\u3001\u30b0\u30eb\u30fc\u30d7\u304c\u591a\u3044\u3068\u5206\u304b\u308a\u3065\u3089\u3044\u3067\u3059\u3057\u3001\u6570\u5b57\u306f\u305a\u308c\u3084\u3059\u3044\u3067\u3059\u3002\u305d\u3046\u3044\u3046\u6642\u306f<span>?&lt;<\/span>\u540d\u524d<span>&gt;<\/span>\u3067\u30b0\u30eb\u30fc\u30d7\u306b\u540d\u524d\u3092\u4ed8\u3051\u307e\u3059\u3002\u3053\u308c\u306f\u300c\u540d\u524d\u4ed8\u304d\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u300d\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(?&lt;year&gt;\\\\d{4})\/(?&lt;month&gt;\\\\d{2})\/(?&lt;day&gt;\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\");\r\n\r\nif (matcher.find()) {\r\n\tString yyyy = matcher.group(\"year\"); \/\/ \u2192 2019\r\n\tString mm = matcher.group(\"month\"); \/\/ \u2192 04\r\n\tString dd = matcher.group(\"day\"); \/\/ \u2192 30\r\n\tSystem.out.println(yyyy + mm + dd); \/\/ \u2192 20190430\r\n}<\/pre>\n<p>\u3042\u3089\u304b\u3058\u3081\u540d\u524d\u3092\u4ed8\u3051\u3066\u304a\u3051\u3070\u3001\u305d\u306e\u540d\u524d\u3067<span>Matcher.group(String)<\/span>\u3092\u547c\u3079\u3070\u3001\u305d\u306e\u90e8\u5206\u306e\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u6b63\u898f\u8868\u73fe\u5185\u306e\u30b0\u30eb\u30fc\u30d7\u306e\u9806\u756a\u304c\u5909\u308f\u3063\u3066\u3082\u6587\u5b57\u5217\u53d6\u5f97\u51e6\u7406\u3092\u5909\u3048\u306a\u304f\u3066\u3082\u3044\u3044\u306e\u3067\u3001\u306a\u304b\u306a\u304b\u4fbf\u5229\u3067\u3059\u3088\u3002<\/p>\n<h3><span id=\"i-14\">\uff15-\uff12\uff0e\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092\u7f6e\u63db\u6642\u306b<span>$<\/span>\u3067\u53c2\u7167\u3059\u308b<\/span><\/h3>\n<p>()\u3067\u306e\u30b0\u30eb\u30fc\u30d7\u5316\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3061\u3089\u306f<span>Matcher.replaceAll<\/span>\u3084<span>replaceFirst<\/span>\u3067\u4f7f\u3048\u308b\u6a5f\u80fd\u3067\u3001\u7f6e\u63db\u5148\u6587\u5b57\u5217\u306e\u4e2d\u3067\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092<span> $ <\/span>\u3067\u53c2\u7167\u3067\u304d\u308b\u306e\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(\\\\d{4})\/(\\\\d{2})\/(\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\");\r\n\r\nif (matcher.find()) {\r\n\tString replaced = matcher.replaceAll(\"$1\u5e74$2\u6708$3\u65e5\");\r\n\tSystem.out.println(replaced); \/\/ \u2192 \u4eca\u65e5\u306f2019\u5e7404\u670830\u65e5\u3067\u3059\u3002\r\n}<\/pre>\n<p>\u5148\u307b\u3069\u306e<span>group<\/span>\u3068\u4f3c\u3066\u3044\u307e\u3059\u306d\u3002<span>matcher.group(1)<\/span>\u306f<span>&#8220;2019&#8221;<\/span>\u3067\u3059\u304c\u3001\u3053\u308c\u304c<span>$1<\/span>\u306b\u5bfe\u5fdc\u3057\u307e\u3059\u3002\u540c\u3058\u3088\u3046\u306b<span>group(2)<\/span>\u306f<span>&#8220;04&#8221;<\/span>\u3067<span>$2<\/span>\u3001<span>group(3)<\/span>\u306f<span>&#8220;30&#8221;<\/span>\u3067<span>$3<\/span>\u3067\u3059\u3002\u3064\u307e\u308a\u3001<span>$<\/span>\u306e\u5f8c\u308d\u306b<span>group<\/span>\u306e\u6570\u5b57\u3092\u4ed8\u3051\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u6587\u5b57\u5217\u3092\u5165\u308c\u66ff\u3048\u308b\u3060\u3051\u306a\u3089<span>group<\/span>\u3092\u3057\u306a\u304f\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u3002<span>replaceAll\/replaceFirst<\/span>\u306e\u7f6e\u63db\u5f8c\u6587\u5b57\u5217\u306b\u5165\u308c\u66ff\u3048\u305f\u3044\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3059\u308b\u3060\u3051\u3067\u3001\u4e26\u3073\u66ff\u3048\u7a0b\u5ea6\u306a\u3089\u30b5\u30af\u30c3\u3068\u6e08\u3093\u3067\u3057\u307e\u3046\u306e\u3067\u3059\u306d\u3002<\/p>\n<p>\u3055\u3089\u306b\u30b0\u30eb\u30fc\u30d7\u306b\u540d\u524d\u3092\u4ed8\u3051\u3066\u3001\u305d\u308c\u3092<span>replaceAll<\/span>\u3067\u306e\u7f6e\u63db\u6587\u5b57\u5217\u306e\u4e2d\u3067\u53c2\u7167\u3055\u305b\u3089\u308c\u307e\u3059\u3002\u3053\u308c\u3082<span>Matcher.group(String)<\/span>\u3068\u540c\u3058\u6a5f\u80fd\u3067\u3059\u3002\u3053\u308c\u3089\u3092\u4f7f\u3048\u3070\u3001\u6587\u5b57\u5217\u7f6e\u63db\u306e\u51e6\u7406\u3092\u3088\u308a\u5206\u304b\u308a\u3084\u3059\u304f\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(?&lt;year&gt;\\\\d{4})\/(?&lt;month&gt;\\\\d{2})\/(?&lt;day&gt;\\\\d{2})\");\r\nMatcher matcher = pattern.matcher(\"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\");\r\n\r\nif (matcher.find()) {\r\n\tString replaced = matcher.replaceAll(\"${year}\u5e74${month}\u6708${day}\u65e5\");\r\n\tSystem.out.println(replaced); \/\/ \u2192 \u4eca\u65e5\u306f2019\u5e7404\u670830\u65e5\u3067\u3059\u3002\r\n}<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001Matcher.replaceAll\u3084replaceFirst\u306f\u3001String.replaceAll\u3068replaceFirst\u306e\u5185\u90e8\u3067\u884c\u308f\u308c\u3066\u3044\u308b\u51e6\u7406\u306a\u306e\u3067\u3001\u5f53\u7136\u306a\u304c\u3089\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3082\u3067\u304d\u308b\u306e\u3067\u3059\u3002\u3053\u308c\u306e\u4f7f\u3044\u65b9\u306f\u3044\u308d\u3044\u308d\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3088<span>!!<\/span><\/p>\n<pre class=\"prettyprint lang:default decode:true\">String str = \"\u4eca\u65e5\u306f2019\/04\/30\u3067\u3059\u3002\";\r\n\r\nString replaced1 = str.replaceAll(\"(\\\\d{4})\/(\\\\d{2})\/(\\\\d{2})\", \"$1\u5e74$2\u6708$3\u65e5\");\r\nString replaced2 = str.replaceAll(\"(?&lt;year&gt;\\\\d{4})\/(?&lt;month&gt;\\\\d{2})\/(?&lt;day&gt;\\\\d{2})\",\r\n\t\t\"${year}\u5e74${month}\u6708${day}\u65e5\");\r\n\r\nSystem.out.println(replaced1); \/\/ \u2192 \u4eca\u65e5\u306f2019\u5e7404\u670830\u65e5\u3067\u3059\u3002\r\nSystem.out.println(replaced2); \/\/ \u2192 \u4eca\u65e5\u306f2019\u5e7404\u670830\u65e5\u3067\u3059\u3002<\/pre>\n<h3><span id=\"i-15\">\uff15-\uff13\uff0e\u6700\u77ed\u4e00\u81f4\u3092\u3055\u305b\u3066\u307f\u308b<\/span><\/h3>\n<p>Java\u306e\u6b63\u898f\u8868\u73fe\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u6700\u9577\u4e00\u81f4\u3068\u547c\u3070\u308c\u308b\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u30de\u30c3\u30c1\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u30de\u30c3\u30c1\u3057\u305f\u4e2d\u3067\u3082\u3063\u3068\u3082\u5e83\u3044\u7bc4\u56f2\u3092\u30de\u30c3\u30c1\u3057\u305f\u7bc4\u56f2\u3068\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u3059\u304c\u3001\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u3042\u3044+\");\r\nMatcher matcher = pattern.matcher(\"\u3042\u3044\u3044\u3044\u3044\u3044\u3044\u3046\u3048\u304a\");\r\n\r\n\/\/ \u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u3042\u308b\u304b\u3092\u78ba\u8a8d\u3057\u3066\u2026\r\nif (matcher.find()) {\r\n\t\/\/ \u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3092print\u3057\u3066\u307f\u308b\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \u3042\u3044\u3044\u3044\u3044\u3044\u3044\r\n}<\/pre>\n<p>\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u306f\u3001<span>&#8220;<\/span>\u3042<span>&#8220;<\/span>\u306e\u5f8c\u308d\u306b<span>&#8220;<\/span>\u3044<span>&#8220;<\/span>\u304c\u3042\u3063\u3066\u3001\u3055\u3089\u306b<span>&#8220;<\/span>\u3044<span>&#8220;<\/span>\u304c<span>1<\/span>\u3064\u4ee5\u4e0a\u9023\u7d9a\u3057\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u3002\u3053\u3053\u3067\u3001\u691c\u7d22\u6587\u5b57\u5217\u304b\u3089\u4e00\u756a\u9577\u304f\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u3092\u63a2\u3059\u306e\u3067<span>(<\/span>\u6700\u9577\u4e00\u81f4<span>)<\/span>\u3001<span>&#8220;<\/span>\u3044<span>&#8220;<\/span>\u304c\u9023\u7d9a\u3057\u3066\u3044\u308b\u6700\u5f8c\u306e\u90e8\u5206\u307e\u3067\u30de\u30c3\u30c1\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u4e00\u756a\u5c11\u306a\u3044\u3068\u3053\u308d\u307e\u3067\u3068\u3059\u308b\u306e\u304c\u300c\u6700\u77ed\u4e00\u81f4\u300d\u3067\u3059\u3002\u6700\u77ed\u4e00\u81f4\u306b\u3059\u308b\u5834\u5408\u306f\u3001\u7e70\u308a\u8fd4\u3057\u3092\u6307\u5b9a\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u306e\u5f8c\u308d\u3078<span>&#8220;?&#8221;<\/span>\u3092\u4ed8\u3051\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u4f8b\u3060\u3068\u3001\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u304c\u4e00\u756a\u77ed\u3044<span>&#8220;<\/span>\u3042\u3044<span>&#8220;<\/span>\u306b\u306a\u308a\u307e\u3057\u305f\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u3042\u3044+?\");\r\nMatcher matcher = pattern.matcher(\"\u3042\u3044\u3044\u3044\u3044\u3044\u3044\u3046\u3048\u304a\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \u3042\u3044\r\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u6b63\u898f\u8868\u73fe\u3067\u306f\u30de\u30c3\u30c1\u3055\u305b\u305f\u3044\u7bc4\u56f2\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<h4>\uff15-\uff13-\uff11\uff0e\u3010\u53c2\u8003\u3011\u5f37\u6b32\u306a\u6570\u91cf\u5b50\u3092\u4f7f\u3063\u3066\u307f\u308b<\/h4>\n<p>Java\u306e\u6b63\u898f\u8868\u73fe\u306b\u306f\u3001\u5c11\u3005\u73cd\u3057\u3044\u6a5f\u80fd\u306e\u300c\u5f37\u6b32\u306a\u6570\u91cf\u5b50<span>(Possessive Quantifiers)<\/span>\u300d\u304c\u3042\u308a\u307e\u3059<span>(<\/span>\u6570\u91cf\u5b50\u306e\u5f8c\u308d\u306b\u3055\u3089\u306b<span>+<\/span>\u3092\u4ed8\u3051\u308b<span>)<\/span>\u3002\u8a00\u8449\u3067\u306e\u8aac\u660e\u306f\u5c11\u3005\u96e3\u3057\u3044\u3067\u3059\u304c\u3001\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30de\u30c3\u30c1\u30f3\u30b0\u306e\u5dee\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern1 = Pattern.compile(\"[a-z]+z\");\r\nPattern pattern2 = Pattern.compile(\"[a-z]++z\");\r\n\r\n\/\/ \u540c\u3058\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u6700\u9577\u4e00\u81f4\u30fb\u5f37\u6b32\u306a\u6570\u91cf\u5b50\u306e\u4e21\u65b9\u3067\u30de\u30c3\u30c1\u3055\u305b\u3066\u307f\u308b\r\nMatcher matcher1 = pattern1.matcher(\"abcdefgz\");\r\nMatcher matcher2 = pattern2.matcher(\"abcdefgz\");\r\n\r\nif (matcher1.find()) {\r\n\tSystem.out.println(matcher1.group(0)); \/\/ \u2192 abcdefgz\r\n} else {\r\n\tSystem.out.println(\"matcher1\u306f\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\");\r\n}\r\n\r\nif (matcher2.find()) {\r\n\tSystem.out.println(matcher2.group(0));\r\n} else {\r\n\tSystem.out.println(\"matcher2\u306f\u30de\u30c3\u30c1\u3057\u307e\u305b\u3093\u3067\u3057\u305f\"); \/\/ \u2192 \u3053\u3061\u3089\r\n}<\/pre>\n<p>\u6700\u521d\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u306f\u3001\u307e\u305a<span>[a-z]+<\/span>\u306e\u90e8\u5206\u3067<span>abcdefgz<\/span>\u306e\u5168\u4f53\u306b\u30de\u30c3\u30c1\u3067\u304d\u307e\u3059\u3088\u306d\u3002\u3067\u3082\u30d1\u30bf\u30fc\u30f3\u306e\u6700\u5f8c\u306b<span>z<\/span>\u304c\u3042\u308b\u306e\u3067\u3001<span>[a-z]+<\/span>\u3067\u30de\u30c3\u30c1\u3059\u308b\u90e8\u5206\u3092\u3061\u3087\u3063\u3068\u3060\u3051\u5c11\u306a\u304f\u3057\u3066\u3001<span>z<\/span>\u3082\u30de\u30c3\u30c1\u3059\u308b\u3088\u3046\u306a\u8abf\u6574\u304c\u81ea\u52d5\u3067\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>\u300c\u5f37\u6b32\u306a\u6570\u91cf\u5b50\u300d\u3060\u3068\u3001<span>[a-z]+<\/span>\u306e\u90e8\u5206\u3067<span>abcdefgz<\/span>\u306e\u5168\u4f53\u306b\u30de\u30c3\u30c1\u3057\u305f\u5f8c\u306b\u3001\u30d1\u30bf\u30fc\u30f3\u6700\u5f8c\u306e<span>z<\/span>\u5411\u3051\u306e\u8abf\u6574\u304c\u5165\u308a\u307e\u305b\u3093\u3002\u30de\u30c3\u30c1\u30f3\u30b0\u7d50\u679c\u3092\u624b\u653e\u3055\u306a\u3044\u306e\u3067\u300c\u5f37\u6b32\u306a\u300d\u306a\u306e\u3067\u3059\u3002\u306a\u306e\u3067\u3001<span>[a-z]++z<\/span>\u3067\u306f\u30de\u30c3\u30c1\u3057\u306a\u3044\u306e\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u5f37\u6b32\u306a\u6570\u91cf\u5b50\u3092\u4f7f\u3046\u306e\u306f\u3001\u4f8b\u3048\u3070\u6b63\u898f\u8868\u73fe\u306e\u30de\u30c3\u30c1\u30f3\u30b0\u51e6\u7406\u306e\u901f\u5ea6\u304c\u5fc5\u8981\u306a\u6642\u3067\u3059\u3002\u524d\u8ff0\u306e\u3068\u304a\u308a\u3001\u5f37\u6b32\u306a\u6570\u91cf\u5b50\u3060\u3068\u518d\u30de\u30c3\u30c1\u3092\u8a66\u307f\u306a\u3044\u306e\u3067\u3001\u305d\u306e\u5206\u51e6\u7406\u304c\u901f\u304f\u306a\u308a\u307e\u3059\u3002\u3067\u3082\u3001\u7d50\u679c\u304c\u9055\u3063\u3066\u304f\u308b\u306e\u3067\u8981\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<h3><span id=\"i-16\">\uff15-\uff14\uff0e\u3010\u767a\u5c55\u3011\u52d5\u4f5c\u3092\u5909\u3048\u308b\u30d5\u30e9\u30b0\u3092\u4f7f\u3063\u3066\u307f\u308b<\/span><\/h3>\n<p>Pattern\u306e\u52d5\u4f5c\u3092\u5909\u3048\u308b\u306b\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u30d5\u30e9\u30b0\u304c\u4f7f\u3048\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30aa\u30fc\u30d0\u30fc\u30ed\u30fc\u30c9\u3055\u308c\u3066\u3044\u308b<span>Pattern.compile(String, int)<\/span>\u306e\u4e8c\u3064\u76ee\u306e<span>int<\/span>\u3078\u6307\u5b9a\u3067\u304d\u308b\u3001<span>Pattern<\/span>\u306e<span>public static<\/span>\u306a\u5b9a\u6570\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ \u30d1\u30bf\u30fc\u30f3\u306f\u82f1\u8a9e\u306e\u5c0f\u6587\u5b57\u3060\u3051\u3060\u304c\u3001\u4fee\u98fe\u5b50\u3068\u3057\u3066\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u7121\u8996(CASE_INSENSITIVE)\u3092\u6307\u5b9a\u3057\u305f\r\nPattern pattern = Pattern.compile(\"[a-z]\", Pattern.CASE_INSENSITIVE);\r\n\/\/ \u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3055\u305b\u308b\u6587\u5b57\u5217\u306f\u3001\u5168\u3066\u82f1\u8a9e\u306e\u5927\u6587\u5b57\u306e\u307f\r\nMatcher matcher = pattern.matcher(\"ABCDEFG\");\r\n\r\n\/\/ \u30d1\u30bf\u30fc\u30f3\u306f\u82f1\u8a9e\u5c0f\u6587\u5b57\u3060\u304c\u3001\u82f1\u8a9e\u5927\u6587\u5b57\u306e\u5bfe\u8c61\u6587\u5b57\u5217\u306b\u3082\u30de\u30c3\u30c1\u3055\u305b\u3089\u308c\u308b\r\nif (matcher.find()) {\r\n\tSystem.out.println(\"\u30de\u30c3\u30c1\u3057\u307e\u3057\u305f\");\r\n}<\/pre>\n<p>\u8907\u6570\u306e\u4fee\u98fe\u5b50\u3092\u540c\u6642\u306b\u6709\u52b9\u306b\u3059\u308b\u5834\u5408\u306f\u3001<span>int<\/span>\u306e\u6570\u5024\u3092\u8ad6\u7406\u548c\u6f14\u7b97\u5b50<span>(|)<\/span>\u3067\u3064\u306a\u304e\u5408\u308f\u305b\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ CASE_INSENSITIVE \u3068 UNICODE_CASE \u3068 UNIX_LINES \u3092\u540c\u6642\u306b\u6709\u52b9\u306b\u3059\u308b\r\nPattern pattern = Pattern.compile(\"[a-z]\",\r\n\tPattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.UNIX_LINES);<\/pre>\n<p>\u3042\u308b\u3044\u306f\u3001\u6b63\u898f\u8868\u73fe\u4e2d\u306b\u7279\u5225\u306a\u6587\u5b57\u3092\u57cb\u3081\u8fbc\u3080\u3053\u3068\u3067\u3082\u3001\u540c\u3058\u52b9\u679c\u304c\u5f97\u3089\u308c\u307e\u3059<span>(<\/span>\u57cb\u3081\u8fbc\u307f\u30d5\u30e9\u30b0\u3068\u547c\u3073\u307e\u3059<span>)<\/span>\u3002\u57cb\u3081\u8fbc\u307f\u30d5\u30e9\u30b0\u3092\u89e3\u9664\u3059\u308b\u306b\u306f\u3001<span>(?-x)<\/span>\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ CASE_INSENSITIVE \u3092\u6b63\u898f\u8868\u73fe\u5185\u3067\u6709\u52b9\u306b\u3059\u308b(?i)\r\nPattern pattern1 = Pattern.compile(\"(?i)[a-z]\");\r\n\/\/ CASE_INSENSITIVE \u3068 UNICODE_CASE \u3068 UNIX_LINES \u3092\u540c\u6642\u306b\u6b63\u898f\u8868\u73fe\u5185\u3067\u6709\u52b9\u306b\u3059\u308b\r\nPattern pattern2 = Pattern.compile(\"(?iud)[a-z]\");<\/pre>\n<p>\u3069\u3046\u3044\u3046\u30d5\u30e9\u30b0\u304c\u3042\u308b\u304b\u306f\u3001<span>Pattern<\/span>\u306e<span>Javadoc<\/span>\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u8aac\u660e\u90e8\u5206\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u308c\u305e\u308c\u306e\u30d5\u30e9\u30b0\u306b\u306f\u3069\u3046\u3044\u3046\u610f\u5473\u304c\u3042\u308b\u304b\u3001\u57cb\u3081\u8fbc\u307f\u30d5\u30e9\u30b0\u3068\u3057\u3066\u306f\u3069\u3046\u6307\u5b9a\u3059\u308c\u3070\u3044\u3044\u306e\u304b\u3082\u304d\u3061\u3093\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3><span id=\"i-17\">\uff15-\uff15\uff0e\u3010\u767a\u5c55\u3011\u5f8c\u65b9\u53c2\u7167\u3092\u3057\u3066\u307f\u308b<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306e\u4e2d\u3067\u3001\u540c\u3058\u30de\u30c3\u30c1\u7d50\u679c\u304c\u51fa\u3066\u304f\u308b\u304b\u8abf\u3079\u305f\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3044\u3046\u3053\u3068\u3092\u6b63\u898f\u8868\u73fe\u306e\u300c\u5f8c\u65b9\u53c2\u7167\u300d\u3092\u4f7f\u3048\u3070\u4e00\u767a\u3067\u51fa\u6765\u305f\u308a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u6b63\u898f\u8868\u73fe\u3067\u7533\u8acb\u8005\u3068\u627f\u8a8d\u8005\u306e\u540d\u524d\u304c\u540c\u3058\u304b\u8abf\u3079\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u7533\u8acb\u8005=(.+?) \u627f\u8a8d\u8005=\\\\1\");\r\n\r\nMatcher matcher1 = pattern.matcher(\"\u7533\u8acb\u8005=\u5c71\u7530\u592a\u90ce \u627f\u8a8d\u8005=\u5c71\u7530\u592a\u90ce\");\r\nMatcher matcher2 = pattern.matcher(\"\u7533\u8acb\u8005=\u5c71\u7530\u592a\u90ce \u627f\u8a8d\u8005=\u9234\u6728\u6b21\u90ce\");\r\n\r\nif (matcher1.find()) {\r\n\tSystem.out.println(matcher1.group(1)); \/\/ \u2192 \u5c71\u7530\u592a\u90ce\u3001()\u304c\u30de\u30c3\u30c1\u3057\u3066\u3044\u308b\u90e8\u5206\u304c \\1 \u306b\u306a\u308b\r\n} else {\r\n\tSystem.out.println(\"\u7533\u8acb\u8005\u3068\u627f\u8a8d\u8005\u306f\u540c\u3058\u3067\u306f\u3042\u308a\u307e\u305b\u3093\");\r\n}\r\n\r\nif (matcher2.find()) {\r\n\tSystem.out.println(matcher2.group(1));\r\n} else {\r\n\tSystem.out.println(\"\u7533\u8acb\u8005\u3068\u627f\u8a8d\u8005\u306f\u540c\u3058\u3067\u306f\u3042\u308a\u307e\u305b\u3093\"); \/\/ \u2192 \u3053\u3061\u3089\r\n}<\/pre>\n<p>\u30d1\u30bf\u30fc\u30f3\u4e2d\u306e<span> \\1 <\/span>\u304c\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002\u3053\u308c\u306f\u5148\u306e<span> (.+?) <\/span>\u306e\u7d50\u679c\u3092\u53c2\u7167\u3057\u3066\u3044\u307e\u3059\u3002\u4ee5\u524d\u306e\u30de\u30c3\u30c1\u7d50\u679c\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u306e\u3067\u300c\u5f8c\u65b9\u53c2\u7167\u300d\u3068\u547c\u3073\u307e\u3059\u3002<span>\\<\/span>\u306e\u5f8c\u308d\u306e\u6570\u5b57\u306f<span> () <\/span>\u306e\u6570\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u3066\u3001<span>Matcher.group(1)<\/span>\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3082\u6570\u5b57\u3067\u306f\u306a\u304f\u6587\u5b57\u3067\u540d\u524d\u3092\u4ed8\u3051\u3089\u308c\u307e\u3059\u3002\u540d\u524d\u306f<span> ?&lt;<\/span>\u540d\u524d<span>&gt; <\/span>\u3067\u3064\u3051\u3066\u3001<span>\\k&lt;<\/span>\u540d\u524d<span>&gt; <\/span>\u3067\u53c2\u7167\u3057\u307e\u3059\u3002\u3053\u308c\u306a\u3089<span> ()<\/span>\u306e\u4f4d\u7f6e\u304c\u5909\u308f\u3063\u3066\u3082\u3001\u540d\u524d\u306f\u5909\u308f\u3089\u306a\u3044\u306e\u3067\u4fbf\u5229\u3067\u3059\u306d\u3002\u8981\u306f<span>Matcher.group(&#8220;person&#8221;)<\/span>\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u7533\u8acb\u8005=(?&lt;person&gt;.+?) \u627f\u8a8d\u8005=\\\\k&lt;person&gt;\");\r\nMatcher matcher = pattern.matcher(\"\u7533\u8acb\u8005=\u5c71\u7530\u592a\u90ce \u627f\u8a8d\u8005=\u5c71\u7530\u592a\u90ce\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(\"person\")); \/\/ \u2192 \u5c71\u7530\u592a\u90ce\r\n} else {\r\n\tSystem.out.println(\"\u7533\u8acb\u8005\u3068\u627f\u8a8d\u8005\u306f\u540c\u3058\u3067\u306f\u3042\u308a\u307e\u305b\u3093\");\r\n}<\/pre>\n<h3><span id=\"i-18\">\uff15-\uff16\uff0e\u3010\u767a\u5c55\u3011\u5148\u8aad\u307f\u30fb\u5f8c\u8aad\u307f\u3092\u3057\u3066\u307f\u308b<\/span><\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306b\u306f\u5148\u8aad\u307f\u3068\u5f8c\u8aad\u307f\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002\u3055\u3089\u306b\u30d1\u30bf\u30fc\u30f3\u304c\u30de\u30c3\u30c1\u3059\u308b\u30fb\u3057\u306a\u3044\u3067\u80af\u5b9a\u3068\u5426\u5b9a\u306e\u4e8c\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u5148\u8aad\u307f\u30fb\u5f8c\u8aad\u307f\u3001\u80af\u5b9a\u30fb\u5426\u5b9a\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3068\u4ee5\u4e0b\u306e\u56db\u7a2e\u985e\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u80af\u5b9a\u5148\u8aad\u307f<\/li>\n<li>\u5426\u5b9a\u5148\u8aad\u307f<\/li>\n<li>\u80af\u5b9a\u5f8c\u8aad\u307f<\/li>\n<li>\u5426\u5b9a\u5f8c\u8aad\u307f<\/li>\n<\/ul>\n<h4>\uff15-\uff16-\uff11\uff0e\u80af\u5b9a\u5148\u8aad\u307f<\/h4>\n<p>\u80af\u5b9a\u5148\u8aad\u307f<span>(?=)<\/span>\u3068\u306f\u3001\u4f55\u304b\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u300c\u5148\u300d\u306b\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d1\u30bf\u30fc\u30f3\u304c\u3055\u3089\u306b\u3042\u308b\u304b\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u666e\u901a\u306e\u30d1\u30bf\u30fc\u30f3\u3068\u306e\u9055\u3044\u306f\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u7d50\u679c\u306b\u306f\u5148\u306b\u3042\u308b\u3068\u6307\u5b9a\u3057\u305f\u30d1\u30bf\u30fc\u30f3\u304c\u542b\u307e\u308c\u306a\u3044\u3053\u3068\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u732b\u306f(?=.+\u304b\u308f\u3044\u3044)\");\r\nMatcher matcher = pattern.matcher(\"\u732b\u306f\u3053\u306e\u5b87\u5b99\u3067\u6700\u3082\u304b\u308f\u3044\u3044\u751f\u7269\u3067\u3059\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \"\u732b\u306f\"\u3001\u5f8c\u308d\u306e\u90e8\u5206\u306f\u30de\u30c3\u30c1\u3057\u3066\u3044\u306a\u3044\r\n}<\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<span>&#8220;<\/span>\u732b\u306f<span>&#8220;<\/span>\u306e\u5f8c\u308d\u306b\u3001\u4f55\u304b\u306e\u6587\u5b57\u304c\u3042\u308a\u3064\u3064<span>&#8220;<\/span>\u304b\u308f\u3044\u3044<span>&#8220;<\/span>\u304c\u3042\u308b\u304b\u80af\u5b9a\u5148\u8aad\u307f\u3067\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002\u5b9f\u969b\u306b\u306f\u6761\u4ef6\u3092\u6e80\u305f\u3059\u306e\u3067<span>find<\/span>\u306f<span>true<\/span>\u3092\u623b\u3057\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u306b\u306f\u5148\u8aad\u307f\u3057\u305f\u90e8\u5206\u306f\u5165\u3063\u3066\u3044\u306a\u3044\u3053\u3068\u306b\u8981\u6ce8\u76ee\u3067\u3059\u3002<\/p>\n<h4>\uff15-\uff16-\uff12\uff0e\u5426\u5b9a\u5148\u8aad\u307f<\/h4>\n<p>\u5426\u5b9a\u5148\u8aad\u307f<span>(?!)<\/span>\u3068\u306f\u3001\u80af\u5b9a\u5148\u8aad\u307f\u306e\u9006\u3067\u3001\u4f55\u304b\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u300c\u5148\u300d\u306b\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d1\u30bf\u30fc\u30f3\u304c\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3067\u306f\u3001\u3053\u308c\u3082\u4f8b\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"\u732b\u306f(?!.+\u304b\u308f\u3044\u304f\u306a\u3044)\");\r\nMatcher matcher = pattern.matcher(\"\u732b\u306f\u3053\u306e\u5b87\u5b99\u3067\u6700\u3082\u304b\u308f\u3044\u3044\u751f\u7269\u3067\u3059\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \"\u732b\u306f\"\u3001\u5f8c\u308d\u306e\u90e8\u5206\u306f\u30de\u30c3\u30c1\u3057\u3066\u3044\u306a\u3044\r\n}<\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<span>&#8220;<\/span>\u732b\u306f<span>&#8220;<\/span>\u306e\u5f8c\u308d\u306b\u306f<span>&#8220;<\/span>\u304b\u308f\u3044\u304f\u306a\u3044<span>&#8220;<\/span>\u3068\u3044\u3046\u6587\u5b57\u5217\u306f\u51fa\u73fe\u3057\u3066\u3044\u307e\u305b\u3093\u3088\u306d\u3002\u3067\u3059\u306e\u3067\u3001<span>find<\/span>\u306e\u7d50\u679c\u306f<span>true<\/span>\u306b\u306a\u308a\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u90e8\u5206\u3082\u80af\u5b9a\u5148\u8aad\u307f\u3068\u540c\u3058\u3088\u3046\u306b<span>&#8220;<\/span>\u732b\u306f<span>&#8220;<\/span>\u3068\u306a\u308b\u306e\u3067\u3059\u3002<\/p>\n<h4>\uff15-\uff16-\uff13\uff0e\u80af\u5b9a\u5f8c\u8aad\u307f<\/h4>\n<p>\u3055\u3066\u3001\u5927\u4f53\u30d1\u30bf\u30fc\u30f3\u306f\u3064\u304b\u3081\u3066\u304d\u305f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u80af\u5b9a\u5f8c\u8aad\u307f<span>(?&lt;=)<\/span>\u3068\u306f\u4f55\u304b\u306e\u30d1\u30bf\u30fc\u30f3\u306e\u300c\u524d\u300d\u306b\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u3082\u4f8b\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(?&lt;=\u304b\u308f\u3044\u3044\u751f\u7269\u306f)\u732b\u3067\u3059\");\r\nMatcher matcher = pattern.matcher(\"\u3053\u306e\u5b87\u5b99\u3067\u6700\u3082\u304b\u308f\u3044\u3044\u751f\u7269\u306f\u732b\u3067\u3059\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \"\u732b\u3067\u3059\"\u3001\u524d\u306e\u90e8\u5206\u306f\u30de\u30c3\u30c1\u3057\u3066\u3044\u306a\u3044\r\n}<\/pre>\n<p>\u305f\u3060\u3057\u3001<span>Java<\/span>\u306e\u5f8c\u8aad\u307f\u3067\u306f\u6570\u91cf\u5b50\u304c\u4f7f\u3048\u307e\u305b\u3093\u3002\u3064\u307e\u308a\u3001<span>+<\/span>\u3068<span>*<\/span>\u304c\u4f7f\u3048\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<span>{}<\/span>\u3068<span>?<\/span>\u306f\u4f7f\u3048\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u5f8c\u8aad\u307f\u306e\u5b9f\u88c5\u96e3\u6613\u5ea6\u304c\u9ad8\u3044\u304b\u3089\u306e\u3088\u3046\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306b\u3088\u3063\u3066\u4f7f\u3048\u308b\u3082\u306e\u304c\u9055\u3046\u306e\u3067\u3059\u3002<\/p>\n<h4>\uff15-\uff16-\uff14\uff0e\u5426\u5b9a\u5f8c\u8aad\u307f<\/h4>\n<p>\u6700\u5f8c\u306e\u5426\u5b9a\u5f8c\u8aad\u307f<span>(?&lt;!)<\/span>\u3082\u4f8b\u3092\u51fa\u3057\u307e\u3059\u3002\u4ed6\u306e\u3082\u306e\u3068\u540c\u3058\u6d41\u308c\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Pattern pattern = Pattern.compile(\"(?&lt;!\u304b\u308f\u3044\u304f\u306a\u3044\u751f\u7269\u306f)\u732b\u3067\u3059\");\r\nMatcher matcher = pattern.matcher(\"\u3053\u306e\u5b87\u5b99\u3067\u6700\u3082\u304b\u308f\u3044\u3044\u751f\u7269\u306f\u732b\u3067\u3059\");\r\n\r\nif (matcher.find()) {\r\n\tSystem.out.println(matcher.group(0)); \/\/ \u2192 \"\u732b\u3067\u3059\"\u3001\u524d\u306e\u90e8\u5206\u306f\u30de\u30c3\u30c1\u3057\u3066\u3044\u306a\u3044\r\n}<\/pre>\n<h2><span id=\"i-19\">\uff16\uff0e\u307e\u3068\u3081<\/span><\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<span>Java<\/span>\u306e<span>Pattern<\/span>\u3092\u8db3\u639b\u304b\u308a\u306b\u3057\u3066\u3001\u6b63\u898f\u8868\u73fe\u306e\u4e16\u754c\u306b\u5c11\u3057\u8db3\u3092\u8e0f\u307f\u5165\u308c\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>Java\u3067\u306e\u6b63\u898f\u8868\u73fe\u306f<span>Pattern.compile<\/span>\u3067<span>Pattern<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u3063\u3066\u4f7f\u3046\u3082\u306e\u3067\u3001\u4e00\u65e6\u4f5c\u3063\u305f<span>Pattern<\/span>\u306f\u6d41\u7528\u304c\u3067\u304d\u308b\u3082\u306e\u3067\u3059\u3002\u305d\u3057\u3066\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u3067\u306f<span>Pattern<\/span>\u304b\u3089<span>Matcher<\/span>\u3092\u751f\u6210\u3057\u3066\u3001\u305d\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>Pattern\u3068<span>Matcher<\/span>\u306e\u91cd\u8981\u306a\u6a5f\u80fd\u306f\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u7d50\u679c\u3092\u5f8c\u304b\u3089\u53c2\u7167\u3067\u304d\u308b\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3067\u3059\u3002\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3092\u4f7f\u3048\u308b\u304b\u3067\u3001\u6587\u5b57\u5217\u51e6\u7406\u306e\u52b9\u7387\u304c\u5927\u304d\u304f\u5909\u308f\u308a\u307e\u3059\u3002\u7c21\u5358\u306a\u3082\u306e\u3067\u3044\u3044\u306e\u3067\u3001\u305c\u3072\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>Java\u306e\u6b63\u898f\u8868\u73fe\u306f\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u3082\u306e\u306b\u8ca0\u3051\u305a\u52a3\u3089\u305a\u5f37\u529b\u3067\u3059\u3002\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u7d44\u307f\u8fbc\u307f\u69cb\u6587\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u5fc5\u8981\u306a\u6a5f\u80fd\u306f\u63c3\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u30ac\u30f3\u30ac\u30f3\u4fbf\u5229\u306b\u6d3b\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u3067Pattern\u3068\u8a00\u3048\u3070\u3001\u6b63\u898f\u8868\u73fe(Regular Expression)\u3067\u4f7f\u3046\u30af\u30e9\u30b9\u306ejava.util.regex.Pattern\u3092\u6307\u3059\u306e\u304c\u666e\u901a\u3067\u3057\u3087\u3046\u3002\u3053\u306ePattern\u3068\u306f\u3001Java\u3067\u6b63\u898f\u8868\u73fe\u306e\u30d1\u30bf\u30fc\u30f3\u3092 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1713"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=1713"}],"version-history":[{"count":8,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1713\/revisions"}],"predecessor-version":[{"id":5811,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1713\/revisions\/5811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/804"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=1713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=1713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}