{"id":1798,"date":"2018-06-12T21:59:41","date_gmt":"2018-06-12T12:59:41","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1798"},"modified":"2020-09-25T22:59:08","modified_gmt":"2020-09-25T13:59:08","slug":"%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1798","title":{"rendered":"\u6b63\u898f\u8868\u73fe"},"content":{"rendered":"<p>\u6587\u5b57\u5217\u5165\u529b\u306e\u691c\u8a3c\u3084\u30c6\u30ad\u30b9\u30c8\u30de\u30a4\u30cb\u30f3\u30b0\u306e\u3088\u3046\u306a\u81ea\u7136\u8a00\u8a9e\u51e6\u7406\u3067\u5e83\u304f\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u6b63\u898f\u8868\u73fe\u3067\u3059\u304c\u3001Python\u306b\u306f\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306ere\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Python\u306e\u6b63\u898f\u8868\u73fe<\/h2>\n<h3>\u6b63\u898f\u8868\u73fe<\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u306f\u30e1\u30bf\u6587\u5b57\u3068\u547c\u3070\u308c\u308b\u6587\u5b57\u3092\u5229\u7528\u3057\u3066\u6587\u5b57\u5217\u306e\u691c\u7d22\u30d1\u30bf\u30fc\u30f3\u3092\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4efb\u610f\u306e\u30c6\u30ad\u30b9\u30c8\u306e\u4e2d\u304b\u3089\u3053\u306e\u691c\u7d22\u30d1\u30bf\u30fc\u30f3\u306b\u5408\u81f4\u3059\u308b\u6587\u5b57\u5217\u3092\u62bd\u51fa\u3057\u305f\u308a\u7f6e\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u30c6\u30ad\u30b9\u30c8\u306e\u6539\u884c\u306e\u307f\u306e\u884c\u306b\u30de\u30c3\u30c1\u3055\u305b\u305f\u3044\u5834\u5408\u3001'^\\n$'\u3068\u8a18\u8ff0\u3057\u307e\u3059\u3002^\u306f\u884c\u982d\u3001\\n\u306f\u6539\u884c\u3092\u8868\u3057\u307e\u3059\u3002\u5b66\u7fd2\u306e\u524d\u306b\u3001\u57fa\u672c\u7684\u306a\u6b63\u898f\u8868\u73fe\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u4fef\u77b0\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u7c21\u5358\u306a\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u6b8a\u6587\u5b57<\/th>\n<th>\u610f\u5473<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>.<\/td>\n<td>\u6539\u884c\u4ee5\u5916\u306e\u4efb\u610f\u306e\u6587\u5b57<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>\u6587\u5b57\u5217\u5148\u982d<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>\u6587\u5b57\u5217\u672b\u5c3e<\/td>\n<\/tr>\n<tr>\n<td>ab|cd<\/td>\n<td>\u6587\u5b57\u5217ab\u304b\u6587\u5b57\u5217cd\u306e\u3069\u3061\u3089\u304b\u306b\u30de\u30c3\u30c1\uff08\u3044\u305a\u308c\u304b\uff09<\/td>\n<\/tr>\n<tr>\n<td>[ab-d]<\/td>\n<td>a\u3068b\u301cd\u306b\u30de\u30c3\u30c1\uff08\u7bc4\u56f2\u6307\u5b9a\uff09<\/td>\n<\/tr>\n<tr>\n<td>[^ab-d]<\/td>\n<td>a\u3068b\u301cd\u4ee5\u5916\u306b\u30de\u30c3\u30c1\uff08\u5426\u5b9a\uff09<\/td>\n<\/tr>\n<tr>\n<td>.(abc).<\/td>\n<td>xabcx\u306a\u3069\u306b\u30de\u30c3\u30c1\uff08\u30b0\u30eb\u30fc\u30d7\u5316\uff09<\/td>\n<\/tr>\n<tr>\n<td>[ab]{2}<\/td>\n<td>a\u304bb\u304c\uff12\u56de\u7e70\u308a\u8fd4\u3055\u308c\u308b<\/td>\n<\/tr>\n<tr>\n<td>[ab]{2,5}<\/td>\n<td>a\u304bb\u304c\uff12\u301c5\u56de\u7e70\u308a\u8fd4\u3055\u308c\u308b<\/td>\n<\/tr>\n<tr>\n<td>[ab]{2,}<\/td>\n<td>a\u304bb\u304c\uff12\u56de\u4ee5\u4e0a\u7e70\u308a\u8fd4\u3055\u308c\u308b<\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>\u76f4\u524d\u306e\u6587\u5b57\u304c\uff11\u56de\u4ee5\u4e0a\u51fa\u73fe<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>\u76f4\u524d\u306e\u6587\u5b57\u304c0\u56de\u4ee5\u4e0a\u51fa\u73fe<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>\u76f4\u524d\u306e\u6587\u5b57\u304c0\u56de\u3082\u3057\u304f\u306f\uff11\u56de\u51fa\u73fe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u30a8\u30b9\u30b1\u30fc\u30d7<\/h3>\n<p>\u7279\u6b8a\u6587\u5b57\u3092\u8868\u3059\u5834\u5408\u306b\u306f\\\u8a18\u53f7\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u307e\u305f\u3001\\\u81ea\u8eab\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u306b\u3082\\\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u7c21\u5358\u306a\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u4f8b<\/th>\n<th>\u610f\u5473<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\\d<\/td>\n<td>\u4efb\u610f\u306e10\u9032\u6570\u6587\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\\D<\/td>\n<td>\u4efb\u610f\u306e\u975e10\u9032\u6570\u6587\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\\w<\/td>\n<td>\u4efb\u610f\u306e\u5358\u8a9e\u6587\u5b57\uff08[a-zA-Z0-9_] \u3068\u7b49\u4fa1\uff09<\/td>\n<\/tr>\n<tr>\n<td>\\W<\/td>\n<td>\u4efb\u610f\u306e\u975e\u5358\u8a9e\u6587\u5b57\uff08[^a-zA-Z0-9_] \u3068\u7b49\u4fa1\uff09<\/td>\n<\/tr>\n<tr>\n<td>\\s<\/td>\n<td>\u4efb\u610f\u306e\u7a7a\u767d\u6587\u5b57\uff08\u30b9\u30da\u30fc\u30b9\u3001\u30bf\u30d6\u3001\\r\u3001\\n\u3001\\v\uff09<\/td>\n<\/tr>\n<tr>\n<td>\\S<\/td>\n<td>\u4efb\u610f\u306e\u975e\u7a7a\u767d\u6587\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>\u5358\u8a9e\u306e\u5883\u754c<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>\u6539\u884c\uff08New Line\uff09<\/td>\n<\/tr>\n<tr>\n<td>\\r<\/td>\n<td>\u30ad\u30e3\u30ea\u30c3\u30b8\u30fb\u30ea\u30bf\u30fc\u30f3<\/td>\n<\/tr>\n<tr>\n<td>\\t<\/td>\n<td>\u30bf\u30d6<\/td>\n<\/tr>\n<tr>\n<td>\\.<\/td>\n<td>\u30d4\u30ea\u30aa\u30c9<\/td>\n<\/tr>\n<tr>\n<td>\\\\<\/td>\n<td>\\\u30de\u30fc\u30af<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>re\u30e2\u30b8\u30e5\u30fc\u30eb<\/h3>\n<p>re\u30e2\u30b8\u30e5\u30fc\u30eb\u306fPython\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3001\u4ee5\u4e0b\u306eimport\u6587\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\n<\/pre>\n<p>\u3088\u304f\u3042\u308b\u6b63\u898f\u8868\u73fe\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u540c\u3058\u304f\u4ee5\u4e0b\u306e\u6a5f\u80fd\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u7f6e\u63db<\/li>\n<li>\u5206\u5272<\/li>\n<li>\u691c\u7d22<\/li>\n<\/ul>\n<h2>\u6b63\u898f\u8868\u73fe\u3067\u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u3092\u7f6e\u63db\u3059\u308b<\/h2>\n<p>\u305d\u308c\u3067\u306fre\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u307e\u305a\u306f\u3001\u30c7\u30fc\u30bf\u30af\u30ec\u30f3\u30b8\u30f3\u30b0\u7b49\u306e\u30c7\u30fc\u30bf\u5206\u6790\u306e\u524d\u51e6\u7406\u3067\u3088\u304f\u4f7f\u7528\u3059\u308b\u6587\u5b57\u5217\u7f6e\u63db\u304b\u3089\u3067\u3059\u3002sub\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u6587\u5b57\u5217\u7f6e\u63db<\/span><\/div>\nre.sub(\u6b63\u898f\u8868\u73fe\u30d1\u30bf\u30fc\u30f3, \u7f6e\u63db\u5f8c\u306e\u6587\u5b57\u5217, \u51e6\u7406\u5bfe\u8c61\u6587\u5b57\u5217)<br \/>\n<\/div>\n<p>\u307e\u305a\u3001\u4ee5\u4e0b\u306e\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n101 CF001    \u30b3\u30fc\u30d2\u30fc\r\n102 CF002    \u30b3\u30fc\u30d2\u30fc\uff08\u304a\u5fb3\u7528\uff09\r\n201 TE01     \u7d05\u8336\r\n202 TE02-A   \u7d05\u8336\uff08\u304a\u5fb3\u7528A\uff09\r\n203 TE02-B   \u7d05\u8336\uff08\u304a\u5fb3\u7528B\uff09\r\n<\/pre>\n<p>\u5546\u54c1id\u3001\u30ab\u30bf\u30ed\u30b0\u30b3\u30fc\u30c9\u3001\u5546\u54c1\u540d\u306e\uff13\u3064\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304b\u3089\u306a\u308b\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002\u30b9\u30da\u30fc\u30b9\u533a\u5207\u308a\u3067\u3059\u304c\u3001\u30b9\u30da\u30fc\u30b9\u306e\u6570\u306f\u4e00\u5b9a\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3053\u306e\u533a\u5207\u308a\u6587\u5b57\u3092\u30bf\u30d6\u306b\u7f6e\u63db\u3057\u3066TSV\u5f62\u5f0f\u306b\u5909\u63db\u3057\u3066\u307f\u307e\u3059\u3002\uff11\u3064\u4ee5\u4e0a\u306e\u30b9\u30da\u30fc\u30b9\u306f' +'\u3067\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u7f6e\u63db\u3059\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;&quot;&quot;101 CF001    \u30b3\u30fc\u30d2\u30fc\r\n102 CF002    \u30b3\u30fc\u30d2\u30fc\uff08\u304a\u5fb3\u7528\uff09\r\n201 TE01     \u7d05\u8336\r\n202 TE02-A   \u7d05\u8336\uff08\u304a\u5fb3\u7528A\uff09\r\n203 TE02-B   \u7d05\u8336\uff08\u304a\u5fb3\u7528B\uff09&quot;&quot;&quot;\r\ntsv_str = re.sub(' +', '\\t', text)\r\n\r\n<\/pre>\n<p>\u53ef\u5909\u9577\u306e\u30b9\u30da\u30fc\u30b9\u533a\u5207\u308a\u6587\u5b57\u5217\u3092\u30bf\u30d6\u533a\u5207\u308a\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n<p>\u3055\u304d\u307b\u3069\u6587\u5b57\u5217\u306e\u7f6e\u63db\u3067re.sub\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u304c\u3001\u5225\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nregex = re.compile(' +')\r\ntsv_str = regex.sub('\\t', text)\r\n<\/pre>\n<p>re.compile\u306b\u3088\u308a\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001re\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u591a\u304f\u306e\u95a2\u6570\u3068\u540c\u69d8\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u7e70\u308a\u8fd4\u3057\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3059\u308b\u307b\u3046\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u6b63\u898f\u8868\u73fe\u3067\u533a\u5207\u3089\u308c\u305f\u6587\u5b57\u5217\u3092\u5206\u5272\u3059\u308b<\/h2>\n<p>split\u3092\u4f7f\u7528\u3059\u308b\u3068\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u305f\u6b63\u898f\u8868\u73fe\u3067\u5206\u5272\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u5206\u5272<\/span><\/div>\nre.split(\u6b63\u898f\u8868\u73fe\u30d1\u30bf\u30fc\u30f3, \u51e6\u7406\u5bfe\u8c61\u6587\u5b57\u5217)<br \/>\n<\/div>\n<p>\u4eca\u5ea6\u306f\u5148\u307b\u3069\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u30921\u30d5\u30a3\u30fc\u30eb\u30c9\u305a\u3064\u533a\u5207\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u533a\u5207\u308a\u306f\u7a7a\u767d\u6587\u5b57\u3068\u6539\u884c\u306a\u306e\u3067\u3001\\s+\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfields = re.split('\\s+', text)\r\nprint(fields)\r\n# ['101', 'CF001', '\u30b3\u30fc\u30d2\u30fc', '102', 'CF0\u30fb\u30fb\u30fb\r\n<\/pre>\n<p>\u307e\u305f\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nregex = re.compile('\\s+')\r\nfields = regex.split(text)\r\n<\/pre>\n<h2>\u6b63\u898f\u8868\u73fe\u3067\u691c\u7d22\u3059\u308b<\/h2>\n<p>\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u304b\u3089\u7279\u5b9a\u306e\u6587\u5b57\u5217\u3092\u691c\u7d22\u3059\u308b\u305f\u3081\u306bre\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u306ffindall\u3001search\u3001match\u3068\u3044\u3046\uff13\u3064\u306e\u691c\u7d22\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>findall\u306b\u3088\u308b\u691c\u7d22<\/h3>\n<p>findall\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u3059\u308b\u3059\u3079\u3066\u306e\u6587\u5b57\u5217\u3092\u30ea\u30b9\u30c8\u3067\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u691c\u7d22<\/span><\/div>\nre.findall(\u691c\u7d22\u6b63\u898f\u8868\u73fe, \u51e6\u7406\u5bfe\u8c61\u6587\u5b57\u5217)<br \/>\n<\/div>\n<p>\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002\u5148\u307b\u3069\u306e\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u304b\u3089\u3059\u3079\u3066\u306e\u300c\u7d05\u8336\u300d\u3092\u542b\u3080\u5217\u3060\u3051\u62bd\u51fa\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u300c\u7d05\u8336\u300d\u3092\u542b\u3080\u6587\u5b57\u5217\u306f\".*\u7d05\u8336.*\"\u3067\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;&quot;&quot;101 CF001    \u30b3\u30fc\u30d2\u30fc\r\n102 CF002    \u30b3\u30fc\u30d2\u30fc\uff08\u304a\u5fb3\u7528\uff09\r\n201 TE01     \u7d05\u8336\r\n202 TE02-A   \u7d05\u8336\uff08\u304a\u5fb3\u7528A\uff09\r\n203 TE02-B   \u7d05\u8336\uff08\u304a\u5fb3\u7528B\uff09&quot;&quot;&quot;\r\n\r\ntea = re.findall(&quot;.*\u7d05\u8336.*&quot;, text)\r\nprint(tea)\r\n# ['201 TE01     \u7d05\u8336', '202 TE02-A   \u7d05\u8336\uff08\u304a\u5fb3\u7528A\uff09', '203 TE02-B   \u7d05\u8336\uff08\u304a\u5fb3\u7528B\uff09']\r\n\r\n# \u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3046\u5834\u5408\r\nregex_tea = re.compile('.*\u7d05\u8336.*')\r\ntea = regex_tea.findall(text)\r\n<\/pre>\n<p>\u300c\u7d05\u8336\u300d\u3092\u542b\u3080\u884c\u304c\u62bd\u51fa\u51fa\u6765\u307e\u3057\u305f\u3002IPython\u306a\u3069\u306e\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u30b7\u30a7\u30eb\u4e0a\u3067grep\u3068\u540c\u69d8\u306e\u51e6\u7406\u3092\u3057\u305f\u3044\u5834\u5408\u306b\u3082\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>search\u306b\u3088\u308b\u691c\u7d22<\/h3>\n<p>search\u306ffindall\u3068\u306f\u7570\u306a\u308a\u3001\u30d1\u30bf\u30fc\u30f3\u306e\u6700\u521d\u306e\u51fa\u73fe\u306e\u958b\u59cb\u4f4d\u7f6e\u3068\u7d42\u4e86\u4f4d\u7f6e\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6301\u3063\u305fmatch\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u691c\u7d22<\/span><\/div>\nre.search(\u691c\u7d22\u6b63\u898f\u8868\u73fe, \u51e6\u7406\u5bfe\u8c61\u6587\u5b57\u5217)<br \/>\n<\/div>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;ABCDEFGHIJKLMNOPQRSTU&quot;\r\nm = re.search('D..G', text)\r\nprint(m.start(), m.end())\r\n# 3 7\r\n\r\nprint(text[m.start():m.end()])\r\n# DEFG\r\n<\/pre>\n<p>\u3068\u306f\u3044\u3048\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u306e\u306f\u9762\u5012\u3067\u3059\u306e\u3067\u3001\u901a\u5e38\u306f\u53d6\u5f97\u3057\u305fmatch\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306egroup\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u4e00\u81f4\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nprint(m.group())\r\n# DEFG\r\n<\/pre>\n<p>\u307e\u305f\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;ABCDEFGHIJKLMNOPQRSTU&quot;\r\nregex = re.compile('D..G')\r\nm = regex.search(text)\r\nprint(m.group())\r\n# DEFG\r\n<\/pre>\n<h3>match\u306b\u3088\u308b\u691c\u7d22<\/h3>\n<p>match\u306f\u5148\u982d\u304b\u3089\u4e00\u81f4\u3057\u305f\u5834\u5408\u306bmatch\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fNone\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u691c\u7d22<\/span><\/div>\nre.match(\u691c\u7d22\u6b63\u898f\u8868\u73fe, \u51e6\u7406\u5bfe\u8c61\u6587\u5b57\u5217)<br \/>\n<\/div>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;ABCDEFGHIJKLMNOPQRSTU&quot;\r\nm = re.match('.*D..G', text)\r\nprint(m.group()) # ABCDEFG\r\n\r\nm = re.match('.*S..V', text)\r\nprint(m) # None\r\n<\/pre>\n<p>\u4e00\u81f4\u3057\u306a\u3044\u5834\u5408\u306fNone\u304c\u8fd4\u3055\u308c\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5148\u982d\u304b\u3089\u4e00\u81f4\u3057\u3066\u3044\u308b\u3072\u3064\u3088\u3046\u304c\u3042\u308b\u305f\u3081\u3001search\u3068\u6bd4\u8f03\u3057\u3066\u3042\u307e\u308a\u4f7f\u7528\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30f3\u30d1\u30a4\u30eb\u6e08\u307f\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;ABCDEFGHIJKLMNOPQRSTU&quot;\r\nregex = re.compile('.*D..G')\r\nm = regex.match(text)\r\nprint(m.group()) # ABCDEFG\r\n<\/pre>\n<h2>\u6b63\u898f\u8868\u73fe\u30b0\u30eb\u30fc\u30d7<\/h2>\n<p>\u6b63\u898f\u8868\u73fe\u30b0\u30eb\u30fc\u30d7\u306f\u3001\u76ee\u7684\u306e\u4e00\u81f4\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30b0\u30eb\u30fc\u30d4\u30f3\u30b0\u3057\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30c7\u30fc\u30bf\u5206\u6790\u3084ETL\u30c4\u30fc\u30eb\u306e\u5b9f\u88c5\u3067\u3088\u304f\u4f7f\u3046\u975e\u5e38\u306b\u4fbf\u5229\u306a\u6a5f\u80fd\u306a\u306e\u3067\u77e5\u3063\u3066\u304a\u304f\u3068\u5f79\u306b\u7acb\u3064\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u5148\u307b\u3069\u306e\u5546\u54c1\u30ea\u30b9\u30c8\u3092\uff11\u30ec\u30b3\u30fc\u30c9\u305a\u3064\u51e6\u7406\u3059\u308b\u5834\u5408\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u5546\u54c1id\u304c\u6570\u5024\u3001\u30ab\u30bf\u30ed\u30b0\u30b3\u30fc\u30c9\u304c\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c9\u5927\u6587\u5b57\u3068\u6570\u5b57\u306e\u7d44\u307f\u5408\u308f\u305b\u3001\u5546\u54c1\u540d\u304c\u4efb\u610f\u306e\u6587\u5b57\u5217\u3067\u3042\u308b\u5834\u5408\u3001\u305d\u308c\u305e\u308c\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5546\u54c1id:[0-9]+<\/li>\n<li>\u30ab\u30bf\u30ed\u30b0\u30b3\u30fc\u30c9:[0-9A-Z]+<\/li>\n<li>\u5546\u54c1\u540d:.*<\/li>\n<li>\u533a\u5207\u308a\u6587\u5b57:\u30b9\u30da\u30fc\u30b9+<\/li>\n<\/ul>\n<p>\u3053\u308c\u3089\u306e\u6b63\u898f\u8868\u73fe\u3092\u30b0\u30eb\u30fc\u30d7\u3067\u8868\u3059\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n([0-9]+) +([0-9A-Z]+) +(.*)\r\n<\/pre>\n<p>\u3053\u306e\u30b0\u30eb\u30fc\u30d7\u3092\u30d1\u30bf\u30fc\u30f3\u3068\u3057\u3066\u6307\u5b9a\u3059\u308b\u3068\u3001\u30bf\u30d7\u30eb\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\ntext = &quot;&quot;&quot;101 CF001    \u30b3\u30fc\u30d2\u30fc\r\n102 CF002    \u30b3\u30fc\u30d2\u30fc\uff08\u304a\u5fb3\u7528\uff09\r\n201 TE01     \u7d05\u8336\r\n202 TE02-A   \u7d05\u8336\uff08\u304a\u5fb3\u7528A\uff09\r\n203 TE02-B   \u7d05\u8336\uff08\u304a\u5fb3\u7528B\uff09&quot;&quot;&quot;\r\n\r\nre.findall('([0-9]+) +([0-9A-Z]+) +(.*)', text)\r\n# [('101', 'CF001', '\u30b3\u30fc\u30d2\u30fc'),\r\n#  ('102', 'CF002', '\u30b3\u30fc\u30d2\u30fc\uff08\u304a\u5fb3\u7528\uff09'),\r\n#  ('201', 'TE01', '\u7d05\u8336')]\r\n<\/pre>\n<p>1\u30ec\u30b3\u30fc\u30c9\u304c1\u30bf\u30d7\u30eb\u3067\u53d6\u5f97\u3067\u304d\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3001\uff11\u3064\u306e\u30c7\u30fc\u30bf\u306e\u584a\u3092\u6b63\u898f\u8868\u73fe\u306e\u30b0\u30eb\u30fc\u30d7\u3068\u3057\u3066\u8868\u305b\u308b\u5834\u5408\u306f\u52b9\u7387\u7684\u306a\u6587\u5b57\u5217\u89e3\u6790\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>Greedy\u3068Lazy<\/h2>\n<p>\u6b63\u898f\u8868\u73fe\u306e\u52d5\u4f5c\u3067\u6ce8\u610f\u3057\u305f\u3044\u306e\u304cGreedy\u3068Lazy\u3067\u3059\u3002<\/p>\n<p>\u6b63\u898f\u8868\u73fe\u304cGreedy\uff08\u8caa\u6b32\uff09\u3068\u306f\u3001\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u3059\u308b\u6587\u5b57\u5217\u3092\u62bd\u51fa\u3057\u305f\u969b\u3001\u30de\u30c3\u30c1\u3059\u308b\u6700\u5927\u7bc4\u56f2\u304c\u62bd\u51fa\u3055\u308c\u308b\u72b6\u6cc1\u3092\u6307\u3057\u307e\u3059\u3002<strong>Python\u306e\u6b63\u898f\u8868\u73fe\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306fGreedy\u306b\u52d5\u4f5c<\/strong>\u3057\u307e\u3059\u3002<\/p>\n<p>\u6587\u7ae0\u3060\u3051\u3060\u3068\u308f\u304b\u308a\u3065\u3089\u3044\u305f\u3081\u3001\u5177\u4f53\u7684\u306a\u30b5\u30f3\u30d7\u30eb\u3092\u6319\u3052\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\nhtml = &quot;&lt;h1&gt;\u898b\u51fa\u3057&lt;\/h1&gt;&lt;p&gt;\u3053\u3053\u306f\u30d1\u30e9\u30b0\u30e9\u30d5\u3067\u3059\u3002&lt;\/p&gt;&quot;\r\np = re.findall('&lt;.*&gt;', html)\r\nprint(p)\r\n# ['&lt;h1&gt;\u898b\u51fa\u3057&lt;\/h1&gt;&lt;p&gt;\u3053\u3053\u306f\u30d1\u30e9\u30b0\u30e9\u30d5\u3067\u3059\u3002&lt;\/p&gt;']\r\n<\/pre>\n<p><font size=\"2.1em\" color=\"red\">2020\/9\/25 \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u4e2d\u306e\u7d50\u679c\u304c\u8aa4\u3063\u3066\u3044\u305f\u305f\u3081\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002\u3054\u9023\u7d61\u304f\u3060\u3055\u3063\u305f\u65b9\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<\/font><\/p>\n<p>\u4e0a\u306e\u6b63\u898f\u8868\u73fe\u3060\u3068<\u304b\u3089\u59cb\u307e\u308a\u3001>\u3067\u7d42\u308f\u308b\u6587\u5b57\u5217\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u7d50\u679c\u3068\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u5168\u4f53\u304c\u30de\u30c3\u30c1\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3082\u3057HTML\u306e\u30bf\u30b0\u3001\u3064\u307e\u308a&lt;h1&gt;\u3001&lt;\/h1&gt;\u3001&lt;p&gt;\u3001&lt;\/p&gt;\u3060\u3051\u3092\u62bd\u51fa\u3057\u305f\u3044\u5834\u5408\u3060\u3068\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u305d\u3093\u306a\u6642\u306b\u4fbf\u5229\u306a\u306e\u304cLazy\uff08\u6020\u60f0\u306a\uff09\u30de\u30c3\u30c1\u30f3\u30b0\u3067\u3059\u3002?\u3092\u30d1\u30bf\u30fc\u30f3\u306e\u6700\u5f8c\u306b\u3064\u3051\u308b\u3068\u3001\u300c\u53ef\u80fd\u306a\u9650\u308a\u5c11\u306a\u3044\u300d\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u518d\u5ea6\u30b5\u30f3\u30d7\u30eb\u3067Lazy\u306a\u30de\u30c3\u30c1\u30f3\u30b0\u306e\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport re\r\nhtml = &quot;&lt;h1&gt;\u898b\u51fa\u3057&lt;\/h1&gt;&lt;p&gt;\u3053\u3053\u306f\u30d1\u30e9\u30b0\u30e9\u30d5\u3067\u3059\u3002&lt;\/p&gt;&quot;\r\np = re.findall('&lt;.*?&gt;', html)\r\nprint(p)\r\n# ['&lt;h1&gt;', '&lt;\/h1&gt;', '&lt;p&gt;', '&lt;\/p&gt;']\r\n<\/pre>\n<p>\u6700\u77ed\u3067\u4e00\u81f4\u3057\u305f\u30bf\u30b0\u306e\u307f\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u5b57\u5217\u5165\u529b\u306e\u691c\u8a3c\u3084\u30c6\u30ad\u30b9\u30c8\u30de\u30a4\u30cb\u30f3\u30b0\u306e\u3088\u3046\u306a\u81ea\u7136\u8a00\u8a9e\u51e6\u7406\u3067\u5e83\u304f\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u6b63\u898f\u8868\u73fe\u3067\u3059\u304c\u3001Python\u306b\u306f\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306ere\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002 Python\u306e\u6b63\u898f\u8868\u73fe \u6b63\u898f\u8868\u73fe \u6b63\u898f\u8868\u73fe\u306f\u30e1\u30bf\u6587\u5b57\u3068\u547c\u3070\u308c...<\/p>\n","protected":false},"author":1,"featured_media":3597,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[75,211],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1798"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1798"}],"version-history":[{"count":19,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1798\/revisions"}],"predecessor-version":[{"id":2614,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1798\/revisions\/2614"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3597"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}