{"id":12529,"date":"2021-05-30T04:00:17","date_gmt":"2021-05-30T09:00:17","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/docs\/php\/%e5%ad%97%e4%b8%b2\/%e6%ad%a3%e8%a6%8f%e5%8a%83%e5%b0%8d%e7%85%a7%e8%a1%a8\/"},"modified":"2021-06-15T21:02:06","modified_gmt":"2021-06-16T02:02:06","slug":"regular-expressions%e3%80%80%e6%ad%a3%e5%89%87%e8%a1%a8%e9%81%94%e5%bc%8f","status":"publish","type":"docs","link":"https:\/\/www.powenko.com\/wordpress\/?docs=php\/%e5%ad%97%e4%b8%b2\/regular-expressions%e3%80%80%e6%ad%a3%e5%89%87%e8%a1%a8%e9%81%94%e5%bc%8f","title":{"rendered":"Regular Expressions\u3000\u6b63\u5247\u8868\u9054\u5f0f"},"content":{"rendered":"<p><span class=\"\">\u6b63\u5247\u8868\u9054\u5f0f\u7121\u975e\u5c31\u662f\u5b57\u7b26\u672c\u8eab\u7684\u5e8f\u5217\u6216\u6a21\u5f0f\u3002<\/span>\u5b83\u5011\u70ba\u6a21\u5f0f\u5c0d\u61c9\u529f\u80fd\u63d0\u4f9b\u4e86\u57fa\u790e\u3002<\/p>\n<p>\u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u60a8\u53ef\u4ee5\u5728\u53e6\u4e00\u500b\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u7279\u5b9a\u5b57\u7b26\u4e32\uff0c\u60a8\u53ef\u4ee5\u7528\u53e6\u4e00\u500b\u5b57\u7b26\u4e32\u66ff\u63db\u4e00\u500b\u5b57\u7b26\u4e32\uff0c\u60a8\u53ef\u4ee5\u5c07\u4e00\u500b\u5b57\u7b26\u4e32\u5206\u6210\u8a31\u591a\u584a\u3002<\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u7279\u5b9a\u65bc\u5169\u7d44\u6b63\u5247\u8868\u9054\u5f0f\u51fd\u6578\u7684\u51fd\u6578\uff0c\u6bcf\u7d44\u51fd\u6578\u5c0d\u61c9\u65bc\u67d0\u7a2e\u985e\u578b\u7684\u6b63\u5247\u8868\u9054\u5f0f\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u81ea\u5df1\u7684\u8212\u9069\u5ea6\u4f7f\u7528\u5b83\u5011\u4e2d\u7684\u4efb\u4f55\u4e00\u500b\u3002<\/p>\n<ul class=\"list\">\n<li>POSIX \u6b63\u5247\u8868\u9054\u5f0f<\/li>\n<li>PERL \u98a8\u683c\u7684\u6b63\u5247\u8868\u9054\u5f0f<\/li>\n<\/ul>\n<h2>POSIX \u6b63\u5247\u8868\u9054\u5f0f<\/h2>\n<p>POSIX \u6b63\u5247\u8868\u9054\u5f0f\u7684\u7d50\u69cb\u8207\u5178\u578b\u7684\u7b97\u8853\u8868\u9054\u5f0f\u7684\u7d50\u69cb\u6c92\u6709\u4ec0\u9ebc\u4e0d\u540c\uff1a\u5404\u7a2e\u5143\u7d20\uff08\u904b\u7b97\u7b26\uff09\u7d44\u5408\u5728\u4e00\u8d77\u5f62\u6210\u66f4\u8907\u96dc\u7684\u8868\u9054\u5f0f\u3002<\/p>\n<p>\u6700\u7c21\u55ae\u7684\u6b63\u5247\u8868\u9054\u5f0f\u662f\u5728g\uff0chaggle\u6216bag\u7b49\u5b57\u7b26\u4e32\u5167\u5c0d\u61c9\u55ae\u500b\u5b57\u7b26\uff08\u4f8b\u5982g\uff09\u7684\u6b63\u5247\u8868\u9054\u5f0f\u3002<\/p>\n<p>\u8b93\u6211\u5011\u89e3\u91cb\u4e00\u4e0b POSIX \u6b63\u5247\u8868\u9054\u5f0f\u4e2d\u4f7f\u7528\u7684\u5e7e\u500b\u6982\u5ff5\u3002\u4e4b\u5f8c\u6211\u5011\u5c07\u5411\u60a8\u4ecb\u7d39\u6b63\u5247\u8868\u9054\u5f0f\u76f8\u95dc\u7684\u529f\u80fd\u3002<\/p>\n<h3>\u62ec\u865f<\/h3>\n<p>\u62ec\u865f ([]) \u5728\u6b63\u5247\u8868\u9054\u5f0f\u7684\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u6642\u5177\u6709\u7279\u6b8a\u542b\u7fa9\u3002\u5b83\u5011\u7528\u65bc\u67e5\u627e\u4e00\u7cfb\u5217\u5b57\u7b26\u3002<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u8868\u9054\u8207\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>[0-9]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u5f9e 0 \u5230 9 \u7684\u4efb\u4f55\u5341\u9032\u5236\u6578\u5b57\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>[az]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u5f9e\u5c0f\u5beb a \u5230\u5c0f\u5beb z \u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>[AZ]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u5f9e\u5927\u5beb A \u5230\u5927\u5beb Z \u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>[aZ]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u5f9e\u5c0f\u5beb a \u5230\u5927\u5beb Z \u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e0a\u9762\u986f\u793a\u7684\u7bc4\u570d\u662f\u4e00\u822c\u7684\uff1b\u60a8\u9084\u53ef\u4ee5\u4f7f\u7528\u7bc4\u570d [0-3] \u4f86\u5c0d\u61c9\u7bc4\u570d\u5f9e 0 \u5230 3 \u7684\u4efb\u4f55\u5341\u9032\u5236\u6578\u5b57\uff0c\u6216\u4f7f\u7528\u7bc4\u570d [bv] \u4f86\u5c0d\u61c9\u7bc4\u570d\u5f9e b \u5230 v \u7684\u4efb\u4f55\u5c0f\u5beb\u5b57\u7b26\u3002<\/p>\n<h3>\u91cf\u8a5e<\/h3>\n<p>\u62ec\u865f\u5167\u7684\u5b57\u7b26\u5e8f\u5217\u548c\u55ae\u500b\u5b57\u7b26\u7684\u983b\u7387\u6216\u4f4d\u7f6e\u53ef\u4ee5\u7528\u7279\u6b8a\u5b57\u7b26\u8868\u793a\u3002\u6bcf\u500b\u7279\u6b8a\u5b57\u7b26\u90fd\u6709\u7279\u5b9a\u7684\u5167\u6db5\u3002+\uff0c*\uff0c\uff1f\uff0c{int\u3002range} \u548c $ \u6a19\u8a8c\u90fd\u9075\u5faa\u4e00\u500b\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u8868\u9054\u8207\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>p+<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u81f3\u5c11\u4e00\u500b p \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>p*<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u96f6\u500b\u6216\u591a\u500b p \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>p?<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u96f6\u500b\u6216\u4e00\u500b p \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>p{\u00a0N\u00a0}<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b<b>N<\/b>\u00a0p\u5e8f\u5217\u7684\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>p{2,3}<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u5169\u500b\u6216\u4e09\u500b p \u5e8f\u5217\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>p{2, }<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u81f3\u5c11\u5169\u500b p \u7684\u5e8f\u5217\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>p$<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u4ee5 p \u7d50\u5c3e\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><b>^\u00a0p<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u4ee5 p \u958b\u982d\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4f8b\u5b50<\/h3>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c07\u6e05\u9664\u60a8\u6709\u95dc\u5c0d\u61c9\u5b57\u7b26\u7684\u6982\u5ff5\u3002<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u8868\u9054\u8207\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>[^a-zA-Z]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u4e0d\u5305\u542b\u5f9e a \u5230 z \u548c A \u5230 Z \u7684\u4efb\u4f55\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>pp<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b p \u7684\u5b57\u7b26\u4e32\uff0c\u5f8c\u8ddf\u4efb\u4f55\u5b57\u7b26\uff0c\u4f9d\u6b21\u5f8c\u8ddf\u53e6\u4e00\u500b p\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>^.{2}$<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u6070\u597d\u5305\u542b\u5169\u500b\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>&lt;b&gt;(.*)&lt;\/b&gt;<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u5305\u542b\u5728 &lt;b&gt; \u548c &lt;\/b&gt; \u4e2d\u7684\u4efb\u4f55\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>p(hp)*<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542bap\u7684\u5b57\u7b26\u4e32\uff0c\u5f8c\u8ddf\u96f6\u500b\u6216\u591a\u500bphp\u5e8f\u5217\u5be6\u4f8b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u9810\u5b9a\u7fa9\u7684\u5b57\u7b26\u7bc4\u570d<\/h3>\n<p>\u70ba\u4e86\u60a8\u7684\u7de8\u7a0b\u65b9\u4fbf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e7e\u500b\u9810\u5b9a\u7fa9\u7684\u5b57\u7b26\u7bc4\u570d\uff0c\u4e5f\u7a31\u70ba\u5b57\u7b26\u985e\u3002\u5b57\u7b26\u985e\u6307\u5b9a\u6574\u500b\u5b57\u7b26\u7bc4\u570d\uff0c\u4f8b\u5982\uff0c\u5b57\u6bcd\u8868\u6216\u6574\u6578\u96c6 &#8211;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u8868\u9054\u8207\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>[[\uff1a\u03b1\uff1a]]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u5b57\u6bcd\u5b57\u7b26 aA \u5230 zZ \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>[[\uff1a\u6578\u5b57\uff1a]]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u6578\u5b57 0 \u5230 9 \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>[[:alnum:]]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u5b57\u6bcd\u6578\u5b57\u5b57\u7b26 aA \u5230 zZ \u548c 0 \u5230 9 \u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>[[:space:]]<\/b><\/p>\n<p>\u5b83\u5c0d\u61c9\u4efb\u4f55\u5305\u542b\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>PHP \u7684 Regexp POSIX \u51fd\u6578<\/h2>\n<p>PHP \u76ee\u524d\u63d0\u4f9b\u4e86\u4e03\u500b\u4f7f\u7528 POSIX \u98a8\u683c\u7684\u6b63\u5247\u8868\u9054\u5f0f\u641c\u7d22\u5b57\u7b26\u4e32\u7684\u51fd\u6578 &#8211;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u529f\u80fd\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td>ereg() \u51fd\u6578\u5728 string \u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u7531 pattern \u6307\u5b9a\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u627e\u5230\u6a21\u5f0f\u5247\u8fd4\u56de true\uff0c\u5426\u5247\u8fd4\u56de false\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td>ereg_replace() \u51fd\u6578\u641c\u7d22\u7531pattern \u6307\u5b9a\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u627e\u5230\u5247\u7528replacement \u66ff\u63dbpattern\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td>eregi() \u51fd\u6578\u5728 pattern \u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22 string \u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u3002\u641c\u7d22\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td>eregi_replace() \u51fd\u6578\u7684\u64cd\u4f5c\u8207 ereg_replace() \u5b8c\u5168\u4e00\u6a23\uff0c\u4e0d\u540c\u4e4b\u8655\u5728\u65bc\u5728\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6a21\u5f0f\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td>split() \u51fd\u6578\u5c07\u4e00\u500b\u5b57\u7b26\u4e32\u5206\u6210\u4e0d\u540c\u7684\u5143\u7d20\uff0c\u6bcf\u500b\u5143\u7d20\u7684\u908a\u754c\u57fa\u65bc\u5b57\u7b26\u4e32\u4e2d\u6a21\u5f0f\u7684\u51fa\u73fe\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td>spliti() \u51fd\u6578\u7684\u64cd\u4f5c\u65b9\u5f0f\u8207\u5176\u5144\u5f1f split() \u5b8c\u5168\u76f8\u540c\uff0c\u53ea\u662f\u5b83\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td>sql_regcase() \u51fd\u6578\u53ef\u4ee5\u88ab\u8a8d\u70ba\u662f\u4e00\u500b\u5be6\u7528\u51fd\u6578\uff0c\u5c07\u8f38\u5165\u53c3\u6578\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u500b\u5b57\u7b26\u8f49\u63db\u70ba\u5305\u542b\u5169\u500b\u5b57\u7b26\u7684\u62ec\u865f\u8868\u9054\u5f0f\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>PERL \u98a8\u683c\u7684\u6b63\u5247\u8868\u9054\u5f0f<\/h2>\n<p>Perl \u6a23\u5f0f\u7684\u6b63\u5247\u8868\u9054\u5f0f\u985e\u4f3c\u65bc\u5b83\u5011\u7684 POSIX \u5c0d\u61c9\u9805\u3002POSIX \u8a9e\u6cd5\u5e7e\u4e4e\u53ef\u4ee5\u8207 Perl \u98a8\u683c\u7684\u6b63\u5247\u8868\u9054\u5f0f\u51fd\u6578\u4e92\u63db\u4f7f\u7528\u3002\u5be6\u969b\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u524d\u9762 POSIX \u90e8\u5206\u4e2d\u4ecb\u7d39\u7684\u4efb\u4f55\u91cf\u8a5e\u3002<\/p>\n<p>\u8b93\u6211\u5011\u89e3\u91cb\u4e00\u4e0b PERL \u6b63\u5247\u8868\u9054\u5f0f\u4e2d\u4f7f\u7528\u7684\u5e7e\u500b\u6982\u5ff5\u3002\u4e4b\u5f8c\u6211\u5011\u5c07\u70ba\u60a8\u4ecb\u7d39\u6b63\u5247\u8868\u9054\u5f0f\u76f8\u95dc\u7684\u529f\u80fd\u3002<\/p>\n<h3>\u5143\u5b57\u7b26<\/h3>\n<p>\u5143\u5b57\u7b26\u53ea\u662f\u4e00\u500b\u5b57\u6bcd\u5b57\u7b26\uff0c\u524d\u9762\u6709\u4e00\u500b\u53cd\u659c\u6760\uff0c\u7528\u65bc\u8ce6\u4e88\u7d44\u5408\u7279\u6b8a\u7684\u542b\u7fa9\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 &#8216;\\d&#8217; \u5143\u5b57\u7b26\u641c\u7d22\u5927\u7b46\u91d1\u984d\uff1a<b>\/([\\d]+)000\/<\/b>\uff0c\u9019\u88e1<b>\\d<\/b>\u5c07\u641c\u7d22\u4efb\u4f55\u6578\u5b57\u5b57\u7b26\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u53ef\u4ee5\u5728 PERL \u6a23\u5f0f\u6b63\u5247\u8868\u9054\u5f0f\u4e2d\u4f7f\u7528\u7684\u5143\u5b57\u7b26\u5217\u8868\u3002<\/p>\n<pre class=\"result notranslate\"><b>Character\t\tDescription<\/b>\r\n. \u55ae\u500b\u5b57\u7b26\r\n\\s \u4e00\u500b\u7a7a\u767d\u5b57\u7b26\uff08\u7a7a\u683c\u3001\u88fd\u8868\u7b26\u3001\u63db\u884c\u7b26\uff09\r\n\\S \u975e\u7a7a\u767d\u5b57\u7b26\r\n\\d \u4e00\u500b\u6578\u5b57 (0-9)\r\n\\D \u4e00\u500b\u975e\u6578\u5b57\r\n\\ w\u4e00\u500b\u5b57\u5143\uff08a-z\uff0cA-Z\uff0c0-9\uff0c_\uff09\r\n\\W \u4e00\u500b\u975e\u55ae\u8a5e\u5b57\u7b26\r\n[aeiou] \u5c0d\u61c9\u7d66\u5b9a\u96c6\u5408\u4e2d\u7684\u55ae\u500b\u5b57\u7b26\r\n[^aeiou] \u5c0d\u61c9\u7d66\u5b9a\u96c6\u5408\u4e4b\u5916\u7684\u55ae\u500b\u5b57\u7b26\r\n(foo|bar|baz) \u5c0d\u61c9\u4efb\u4f55\u6307\u5b9a\u7684\u66ff\u4ee3\u65b9\u6848\r\n<\/pre>\n<h3>\u4fee\u98fe\u7b26<\/h3>\n<p>\u6709\u5e7e\u500b\u4fee\u98fe\u7b26\u53ef\u4ee5\u8b93\u60a8\u66f4\u8f15\u9b06\u5730\u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u4f8b\u5982\u5340\u5206\u5927\u5c0f\u5beb\u3001\u591a\u884c\u641c\u7d22\u7b49\u3002<\/p>\n<pre class=\"result notranslate\">\u4fee\u98fe\u7b26\u8aaa\u660e\r\ni \u4f7f\u5c0d\u61c9\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\r\nm \u6307\u5b9a\u5b57\u7b26\u4e32\u662f\u5426\u6709\u63db\u884c\u7b26\u6216\u56de\u8eca\u7b26\r\n\u3000\u8fd4\u56de\u5b57\u7b26\uff0c^ \u548c $ \u904b\u7b97\u7b26\u73fe\u5728\u5c07\r\n\u3000\u5c0d\u61c9\u63db\u884c\u908a\u754c\uff0c\u800c\u4e0d\u662f\r\n\u3000\u5b57\u7b26\u4e32\u908a\u754c\r\no \u53ea\u8a08\u7b97\u8868\u9054\u5f0f\u4e00\u6b21\r\ns \u5141\u8a31\u4f7f\u7528 . \u5c0d\u61c9\u63db\u884c\u7b26\r\nx \u5141\u8a31\u60a8\u5728\u8868\u9054\u5f0f\u4e2d\u4f7f\u7528\u7a7a\u683c\u4ee5\u4fdd\u6301\u6e05\u6670\r\ng \u5168\u5c40\u67e5\u627e\u6240\u6709\u5c0d\u61c9\u9805\r\ncg \u5141\u8a31\u5728\u5168\u5c40\u5c0d\u61c9\u5931\u6557\u5f8c\u7e7c\u7e8c\u641c\u7d22\r\n<\/pre>\n<h2>PHP \u7684 Regexp PERL \u517c\u5bb9\u51fd\u6578<\/h2>\n<p>PHP \u63d0\u4f9b\u4ee5\u4e0b\u4f7f\u7528 Perl \u517c\u5bb9\u7684\u6b63\u5247\u8868\u9054\u5f0f\u641c\u7d22\u5b57\u7b26\u4e32\u7684\u529f\u80fd &#8211;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th class=\"ts\">\u5e8f\u865f<\/th>\n<th class=\"ts\">\u529f\u80fd\u8aaa\u660e<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td>preg_match() \u51fd\u6578\u5728\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6a21\u5f0f\uff0c\u5982\u679c\u6a21\u5f0f\u5b58\u5728\u5247\u8fd4\u56de\u771f\uff0c\u5426\u5247\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><a href=\"httpss:\/\/www.powenko.com\/wordpress\/docs\/php\/%e5%ad%97%e4%b8%b2\/preg_replace-%e5%ad%97%e4%b8%b2%e6%9b%bf%e6%8f%9b\/\">preg_match_all()<\/a> \u51fd\u6578\u5c0d\u61c9\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u51fa\u73fe\u7684\u6a21\u5f0f\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td>preg_replace() \u51fd\u6578\u7684\u64cd\u4f5c\u8207 ereg_replace() \u985e\u4f3c\uff0c\u4e0d\u540c\u4e4b\u8655\u5728\u65bc\u6b63\u5247\u8868\u9054\u5f0f\u53ef\u7528\u65bc\u6a21\u5f0f\u548c\u66ff\u63db\u8f38\u5165\u53c3\u6578\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td>preg_split() \u51fd\u6578\u7684\u64cd\u4f5c\u8207 split() \u5b8c\u5168\u4e00\u6a23\uff0c\u53ea\u662f\u6b63\u5247\u8868\u9054\u5f0f\u88ab\u63a5\u53d7\u70ba\u6a21\u5f0f\u7684\u8f38\u5165\u53c3\u6578\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td>preg_grep() \u51fd\u6578\u641c\u7d22 input_array \u7684\u6240\u6709\u5143\u7d20\uff0c\u8fd4\u56de\u8207\u6b63\u5247\u8868\u9054\u5f0f\u6a21\u5f0f\u5c0d\u61c9\u7684\u6240\u6709\u5143\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td>preg_quote()\u5f15\u7528\u6b63\u5247\u8868\u9054\u5f0f\u5b57\u7b26<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div><\/div>\n<div class=\"pre-btn\"><\/div>\n<div><\/div>\n<div>\n<h2>\u5c0d\u61c9\u8a72\u5b57\u7b26\uff0c\u5247\u61c9\u8f49\u7fa9\u4ee5\u4e0b\u5167\u5bb9<\/h2>\n<p>\\^\u3002 $ | ( ) [ ]<br \/>\n* + ? { } ,<\/p>\n<p>\u7279\u6b8a\u5b57\u7b26\u5b9a\u7fa9<br \/>\n\\ \u5f15\u7528\u4e0b\u4e00\u500b\u5143\u5b57\u7b26<br \/>\n^ \u5c0d\u61c9\u884c\u9996<br \/>\n.\u5c0d\u61c9\u4efb\u4f55\u5b57\u7b26\uff08\u63db\u884c\u7b26\u9664\u5916\uff09<br \/>\n$\u5c0d\u61c9\u884c\u5c3e\uff08\u6216\u884c\u5c3e\u63db\u884c\u4e4b\u524d\uff09<br \/>\n|\u4ea4\u66ff<br \/>\n() \u5206\u7d44<br \/>\n[] \u5b57\u7b26\u985e<br \/>\n* \u5c0d\u61c9 0 \u6b21\u6216\u591a\u6b21<br \/>\n+ \u5c0d\u61c9 1 \u6b21\u6216\u591a\u6b21<br \/>\n?\u5c0d\u61c9 1 \u6b21\u6216 0 \u6b21<br \/>\n{n} \u6b63\u597d\u5c0d\u61c9 n \u6b21<br \/>\n{n,} \u81f3\u5c11\u5c0d\u61c9 n \u6b21<br \/>\n{n,m} \u5c0d\u61c9\u81f3\u5c11 n \u4f46\u4e0d\u8d85\u904e m \u6b21<br \/>\n\u66f4\u591a\u7279\u6b8a\u89d2\u8272\u7684\u6771\u897f<br \/>\n\\t \u88fd\u8868\u7b26 (HT, TAB)<br \/>\n\\n \u63db\u884c\u7b26 (LF, NL)<br \/>\n\\ r\u8fd4\u56de\uff08CR\uff09<br \/>\n\\f \u63db\u9801 (FF)<br \/>\n\\a \u9b27\u9418 (bell) (BEL)<br \/>\n\\e \u8f49\u7fa9\uff08\u60f3\u60f3 troff\uff09\uff08ESC\uff09<br \/>\n\\033 \u516b\u9032\u88fd\u5b57\u7b26\uff08\u60f3\u60f3 PDP-11\uff09<br \/>\n\\x1B \u5341\u516d\u9032\u88fd\u5b57\u7b26<br \/>\n\\c[ \u63a7\u88fd\u5b57\u7b26<br \/>\n\\l \u5c0f\u5beb\u4e0b\u4e00\u500b\u5b57\u7b26\uff08\u60f3\u60f3 vi\uff09<br \/>\n\\u \u5927\u5beb\u4e0b\u4e00\u500b\u5b57\u7b26\uff08\u60f3\u60f3 vi\uff09<br \/>\n\\L \u5c0f\u5beb\u76f4\u5230 \\E\uff08\u60f3\u60f3 vi\uff09<br \/>\n\\U \u5927\u5beb\u76f4\u5230 \\E\uff08\u60f3\u60f3 vi\uff09<br \/>\n\\E \u7d50\u675f\u6848\u4f8b\u4fee\u6539\uff08\u60f3\u60f3 vi\uff09<br \/>\n\\ Q\u5f15\u7528\uff08\u7981\u7528\uff09\u6a21\u5f0f\u5143\u5b57\u7b26\uff0c\u76f4\u5230\\ E<br \/>\n\u751a\u81f3\u66f4\u591a\u7279\u6b8a\u5b57\u7b26<br \/>\n\\w \u5c0d\u61c9\u4e00\u500b\u201c\u55ae\u8a5e\u201d\u5b57\u7b26\uff08\u5b57\u6bcd\u6578\u5b57\u52a0\u201c_\u201d\uff09<br \/>\n\\W \u5c0d\u61c9\u4e00\u500b\u975e\u55ae\u8a5e\u5b57\u7b26<br \/>\n\\s \u5c0d\u61c9\u4e00\u500b\u7a7a\u767d\u5b57\u7b26<br \/>\n\\S \u5c0d\u61c9\u4e00\u500b\u975e\u7a7a\u767d\u5b57\u7b26<br \/>\n\\d \u5c0d\u61c9\u4e00\u500b\u6578\u5b57\u5b57\u7b26<br \/>\n\\D \u5c0d\u61c9\u4e00\u500b\u975e\u6578\u5b57\u5b57\u7b26<br \/>\n\\b \u5c0d\u61c9\u55ae\u8a5e\u908a\u754c<br \/>\n\\B \u5c0d\u61c9\u4e00\u500b\u975e\uff08\u8a5e\u908a\u754c\uff09<br \/>\n\\A \u50c5\u5728\u5b57\u7b26\u4e32\u958b\u982d\u5c0d\u61c9<br \/>\n\\Z \u53ea\u5c0d\u61c9\u5b57\u7b26\u4e32\u7684\u7d50\u5c3e\uff0c\u6216\u8005\u7d50\u5c3e\u7684\u63db\u884c\u7b26\u4e4b\u524d<br \/>\n\\z \u53ea\u5728\u5b57\u7b26\u4e32\u672b\u5c3e\u5c0d\u61c9<br \/>\n\\G \u50c5\u5c0d\u61c9\u524d\u4e00\u500b m\/\/g \u505c\u6b62\u7684\u5730\u65b9\uff08\u50c5\u9069\u7528\u65bc \/g\uff09<\/p>\n<\/div>\n","protected":false},"featured_media":0,"parent":12466,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-12529","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12529"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12529"}],"version-history":[{"count":8,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12529\/revisions"}],"predecessor-version":[{"id":12538,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12529\/revisions\/12538"}],"up":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12466"}],"next":[{"title":"URL\u8def\u5f91..\/..\/ \u7684\u5f8c\u7684\u4f4d\u7f6e","link":"https:\/\/www.powenko.com\/wordpress\/?docs=php\/%e5%ad%97%e4%b8%b2\/url%e8%b7%af%e5%be%91-%e7%9a%84%e5%be%8c%e7%9a%84%e4%bd%8d%e7%bd%ae","href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12779"}],"prev":[{"title":"preg_replace\b \u5b57\u4e32\u66ff\u63db","link":"https:\/\/www.powenko.com\/wordpress\/?docs=php\/%e5%ad%97%e4%b8%b2\/preg_replace-%e5%ad%97%e4%b8%b2%e6%9b%bf%e6%8f%9b","href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12519"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12529"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=12529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}