{"id":622,"date":"2008-11-01T14:11:03","date_gmt":"2008-11-01T06:11:03","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/622.aspx"},"modified":"2008-11-01T08:11:56","modified_gmt":"2008-11-01T00:11:56","slug":"Mootools+1.2%e6%95%99%e7%a8%8b(13)%e2%80%94%e2%80%94%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/622","title":{"rendered":"Mootools 1.2\u6559\u7a0b(13)\u2014\u2014\u6b63\u5219\u8868\u8fbe\u5f0f"},"content":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.consideropen.com\/blog\/2008\/08\/30-days-of-mootools-12-tutorials-day-13-regular-expressions\/\" target=\"_blank\" title=\"30 Days of Mootools 1.2 Tutorials - Day 13 - Regular Expressions\">30 Days of Mootools 1.2 Tutorials &#8211; Day 13 &#8211; Regular Expressions<\/a><\/p>\n<h2>MooTools\u548c\u6b63\u5219\u8868\u8fbe\u5f0f<\/h2>\n<p>\u8bf7\u5c0a\u91cd\u4e2a\u4eba\u52b3\u52a8\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttp:\/\/fdream.net\uff0c \u8bd1\u8005\uff1aFdream<\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u51c6\u5907\u597d\u5f00\u59cb\u8fd9\u4e00\u8bb2\uff0c\u6211\u5efa\u8bae\u4f60\u5148\u770b\u8fd9\u4e00\u7cfb\u5217\u7684\u6559\u7a0b\u7684\u524d\u9762\u4e00\u90e8\u5206\uff0c\u8fd9\u91cc\u662f<a href=\"http:\/\/fdream.net\/blog\/article\/605.aspx\" target=\"_blank\" title=\"\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b\">\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b<\/a>\u3002<\/p>\n<p>\u4eca\u5929\u6211\u4eec\u5c06\u5148\u7b80\u8981\u5730\u770b\u4e00\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u518d\u770b\u4e00\u4e0bMooTools\u63d0\u4f9b\u7684\u4e00\u4e9b\u8ba9\u6b63\u5219\u8868\u8fbe\u5f0f\u66f4\u5bb9\u6613\u4f7f\u7528\u7684\u529f\u80fd\u3002\u5982\u679c\u4f60\u8fd8\u4e0d\u719f\u6089\u600e\u4e48\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff08regular expression\uff08regex\uff09\uff09\uff0c\u6211\u5f3a\u70c8\u5efa\u8bae\u4f60\u82b1\u4e00\u5b9a\u91cf\u7684\u65f6\u95f4\u597d\u597d\u770b\u4e00\u4e0b\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u7684\u4e00\u4e9b\u94fe\u63a5\uff0c\u5c24\u5176\u662f\u6587\u7ae0\u7ed3\u5c3e\u201c\u66f4\u591a\u5b66\u4e60\u201d\u90e8\u5206\u7684\u94fe\u63a5\u3002\u6211\u4eec\u4eca\u5929\u53ea\u662f\u8bb2\u4e00\u8bb2\u6b63\u5219\u8868\u8fbe\u5f0f\u6700\u57fa\u672c\u7684\u7528\u6cd5\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u80fd\u505a\u7684\u8fdc\u8fdc\u8d85\u8fc7\u6211\u4eec\u4eca\u5929\u6240\u8bb2\u7684\u5185\u5bb9\u3002<\/p>\n<h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<p><b>test()\u65b9\u6cd5<\/b><\/p>\n<p>\u5b83\u7684\u7b80\u5355\u5728\u4e8e\uff0c\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u662f\u4e00\u4e2a\u4f60\u60f3\u8981\u5339\u914d\u7684\u7b80\u5355\u5b57\u7b26\u4e32\u3002\u5c3d\u7ba1JavaScript\u672c\u8eab\u5df2\u7ecf\u4e3a<a href=\"http:\/\/developer.mozilla.org\/en\/Core_JavaScript_1.5_Reference\/Objects\/RegExp\" target=\"_blank\" title=\"RegExp\u5bf9\u8c61\">RegExp\u5bf9\u8c61<\/a>\u63d0\u4f9b\u4e86\u5b83\u81ea\u5df1\u7684<a href=\"http:\/\/developer.mozilla.org\/en\/Core_JavaScript_1.5_Reference\/Objects\/RegExp\/test\" target=\"_blank\" title=\"test()\u65b9\u6cd5\">test()\u65b9\u6cd5<\/a>\uff0cMooTools\u7684test()\u65b9\u6cd5\u66f4\u597d\u7528\u4e00\u4e9b\uff0c\u5728JavaScript\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4e5f\u66f4\u8f7b\u677e\u4e00\u4e9b\u3002<\/p>\n<p>\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0btest()\u65b9\u6cd5\u6700\u7b80\u5355\u7684\u7528\u6cd5\uff0c\u5728\u4e00\u4e2a\u5927\u7684\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u5728\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\nvar string_to_test = &quot;Match anything in here&quot;;\n \n\/\/ \u6211\u4eec\u8981\u67e5\u627e\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\nvar regular_expression = &quot;anything&quot;;\n \n\/\/ \u5e94\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8fd4\u56detrue\u6216\u8005false\nvar result = string_to_test.test(regular_expression);\n \n\/\/ result\u73b0\u5728\u4e3atrue\n<\/pre>\n<\/p>\n<p>\u8fd9\u548ccontains()\u51fd\u6570\u7684\u884c\u4e3a\u57fa\u672c\u7c7b\u4f3c\uff0c\u4e0d\u8fc7contains\u662f\u6309\u7167\u5b8c\u6574\u7684\u5355\u8bcd\u67e5\u627e\uff0c\u800c\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u4efb\u4f55\u5b83\u51fa\u73b0\u7684\u5730\u65b9\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5728\u4e0b\u9762\u7684\u8fd9\u4e2a\u5b9e\u4f8b\u4e2d\uff0ccontains()\u65b9\u6cd5\u5c06\u4e0d\u8fd4\u56detrue\uff0c\u800ctest()\u65b9\u6cd5\u5c06\u8fd4\u56detrue\u3002\uff08Fdream\u6ce8\uff1a\u7ecftaoyu3781212\u7684\u63d0\u9192\uff0c\u8fd9\u4e2a\u8bf4\u6cd5\u662f\u4e0d\u6b63\u786e\u7684\u3002\u5b9e\u9645\u4e0a\uff0ccontains()\u65b9\u6cd5\u53ef\u4ee5\u6307\u5b9a\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u67e5\u627e\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u662f\u5206\u9694\u5b57\u7b26\u4e32\uff0c\u53ea\u6709\u5f53\u6307\u5b9a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u65f6\uff0ccontains()\u65b9\u6cd5\u624d\u4f1a\u8fd4\u56defalse\uff0c\u8fd9\u4e2a\u5b9e\u9645\u4e0a\u5c31\u662farray\u7684contains()\u65b9\u6cd5\u3002\uff09<\/p>\n<p><pre lang=\"javascript\">\nvar string_to_match = &quot;anything else&quot;;\n \n\/\/ \u8fd4\u56detrue\nstring_to_match.contains('nything')\n \n\/\/ \u8fd4\u56defalse\nstring_to_match.contains('nything', ' ')\n \n\/\/ \u8fd4\u56detrue\nstring_to_match.contains('anything')\n \n\/\/ \u8fd4\u56detrue\nstring_to_match.test('nything');\n<\/pre>\n<\/p>\n<p>\u53e6\u5916\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9664\u975e\u4f60\u660e\u786e\u6307\u5b9a\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u56e0\u6b64\u4f60\u5728\u4e00\u4e2a\u5305\u542b\u201cMatch\u201d\u7684\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u201cmatch\u201d\u5c06\u8fd4\u56defalse\u3002\u4f60\u53ef\u4ee5\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u8bd5\u4e00\u8bd5\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar regex_demo = function(){\n    var test_string = $('regex_1_value').get('value');\n    var regex_value = $('regex_1_match').get('value');\n    var test_result = test_string.test(regex_value);\n \n    if(test_result){\n        $('regex_1_result').set('html', &quot;matched&quot;);\n    }\n    else {\n        $('regex_1_result').set('html', &quot;didn't match&quot;);\n    }\n}\n<\/pre>\n<\/p>\n<p>\u6ce8\u610f\uff0c\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u6709\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\uff0c\u4f60\u9700\u8981\u5c0f\u5fc3\u4f7f\u7528\u3002\u5982\u679c\u4f60\u628a\u8fd9\u4e9b\u5b57\u7b26\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u8f93\u5165\u5230\u4e0b\u9762\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6587\u672c\u6846\u4e2d\u5c06\u4f1a\u4ea7\u751f\u9519\u8bef\uff0c\u8fd9\u4e2a\u65f6\u5019\u4f60\u9700\u8981\u5237\u65b0\u8fd9\u4e2a\u9875\u9762\u624d\u80fd\u7ee7\u7eed\u4e0b\u9762\u7684\u6f14\u793a\u4f8b\u5b50\u3002<\/p>\n<p>&#8211; . * + ? ^ $ { } ( ) | [ ] \/ \\<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_1 = function(){\n    var test_string = $('regex_1_value').get('value');\n    var regex_value = $('regex_1_match').get('value');\n    var test_result = test_string.test(regex_value);<\/p>\n<p>    if     (test_result){$('regex_1_result').set('html', \"matched\");}\n    else {$('regex_1_result').set('html', \"didn't match\");}\n}\n<\/script><\/p>\n<style type=\"text\/css\">\ninput.t_text{background:none;background:#fff;color:#000}\n<\/style>\n<p>\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\uff1a<input id=\"regex_1_value\" class=\"t_text\" type=\"text\" value=\"Match any of these words\" \/><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_1_match\" class=\"t_text\" type=\"text\" value=\"any\" \/><br \/>\n<input onclick=\"regex_demo_1()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\u00a0<span id=\"regex_1_result\"><\/span>\n<\/p>\n<p><b>\u5ffd\u7565\u5927\u5c0f\u5199<\/b><\/p>\n<p>\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u4f60\u4e0d\u9700\u8981\u5173\u5fc3\u4f60\u8981\u5339\u914d\u7684\u9879\u7684\u5927\u5c0f\u5199\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u8981\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u5927\u5c0f\u5199\u654f\u611f\uff0c\u4f60\u53ef\u4ee5\u5728\u8c03\u7528test()\u65b9\u6cd5\u65f6\u6dfb\u52a0\u4e00\u4e2a\u53c2\u6570\u201ci\u201d\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u5728\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\nvar string_to_test = &quot;IgNorE CaSe&quot;;\n \n\/\/ \u8fd4\u56defalse\nstring_to_test.test(&quot;ignore&quot;);\n \n\/\/ \u8fd4\u56detrue\nstring_to_test.test(&quot;ignore&quot;, &quot;i&quot;);\n<\/pre>\n<\/p>\n<p>\u4ece\u6280\u672f\u4e0a\u8bb2\uff0c\u4f60\u53ef\u4ee5\u4f20\u9012\u591a\u4e2a\u53c2\u6570\u7ed9test()\u65b9\u6cd5\uff0c\u4f46\u662f\u7531\u4e8eJavaScript\u73b0\u5728\u4ec5\u4ec5\u53ea\u652f\u63013\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u53c2\u6570\uff08\u5176\u4e2d2\u4e2a\u5728test()\u65b9\u6cd5\u4e2d\u9ed8\u8ba4\u542f\u7528\uff09\uff0c\u8fd9\u4e2a\u671f\u95f4\u5185\u4f60\u53ef\u80fd\u4ec5\u4ec5\u53ea\u80fd\u4f7f\u7528\u53c2\u6570\u201ci\u201d\u3002\u4f60\u53ef\u4ee5\u7ee7\u7eed\u6d4b\u8bd5\u4e00\u4e0b\u5927\u5c0f\u5199\u5339\u914d\u7684\u4e0d\u540c\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar regex_demo = function(){\n    \/\/ \u4ece\u8f93\u5165\u6587\u672c\u6846\u4e2d\u5f97\u5230\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\n    var test_string = $('regex_2_value').get('value');\n \n    \/\/ \u4ece\u8f93\u5165\u6587\u672c\u6846\u4e2d\u5f97\u5230\u6b63\u5219\u8868\u8fbe\u5f0f\n    var regex_value = $('regex_2_match').get('value');\n \n    \/\/ \u5982\u679c\u6211\u4eec\u9700\u8981\u5ffd\u7565\u5927\u5c0f\u5199\n    var regex_param = &quot;&quot;;\n    if ($('regex_2_param').checked){\n        regex_param = &quot;i&quot;;\n    }\n \n    \/\/ \u8fd0\u884ctest()\u65b9\u6cd5\u5e76\u5f97\u5230\u7ed3\u679c\n    var test_result = test_string.test(regex_value, regex_param);\n \n    \/\/ \u66f4\u65b0\u7ed3\u679c\u663e\u793a\u533a\u57df\n    if (test_result){\n        $('regex_2_result').set('html', &quot;matched&quot;);\n    }\n    else {\n        $('regex_2_result').set('html', &quot;didn't match&quot;);\n    }\n}\n<\/pre>\n<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_2 = function(){\n    var test_string = $('regex_2_value').get('value');\n    var regex_value = $('regex_2_match').get('value');\n    var regex_param = \"\";\n    if ($('regex_2_param').checked){\n        regex_param = \"i\";\n    }\n    var test_result = test_string.test(regex_value, regex_param);\n    if (test_result){\n        $('regex_2_result').set('html', \"matched\");\n    }\n    else {\n        $('regex_2_result').set('html', \"didn't match\");\n    }\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\uff1a<input id=\"regex_2_value\" class=\"t_text\" type=\"text\" value=\"IgNorE CaSe\" \/><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_2_match\" class=\"t_text\" type=\"text\" value=\"ignore\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_2_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_2()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\u00a0<span id=\"regex_2_result\"><\/span>\n<\/p>\n<h3>\u6709\u8da3\u7684\u4e8b\u60c5<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u5b66\u4f1a\u4e86\u7b80\u5355\u7684\u5339\u914d\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u770b\u4e00\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\u66f4\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u7684\u4e00\u4e9b\u65b9\u9762\u3002\u8fd9\u91cc\u4e0d\u4f1a\u6db5\u76d6\u4e00\u5207\u53ef\u80fd\u4e0e\u6b63\u5219\u8868\u8fbe\u5f0f\u76f8\u5173\u7684\u4e1c\u897f\u2014\u2014\u6211\u4eec\u5c06\u6311\u9009\u4e00\u4e9b\u66f4\u76f4\u63a5\u66f4\u6709\u7528\u7684\u529f\u80fd\u3002<\/p>\n<p><b>\u4f7f\u7528^\u4ece\u5b57\u7b26\u4e32\u5f00\u59cb\u5339\u914d<\/b><\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u201c^\u201d\u8fd0\u7b97\u7b26\u5141\u8bb8\u4f60\u5728\u4e00\u884c\u5b57\u7b26\u4e32\u7684\u5f00\u5934\u5339\u914d\uff0c\u800c\u4e0d\u7ba1\u5b57\u7b26\u7684\u540e\u9762\u6709\u6ca1\u6709\u76f8\u5e94\u7684\u5339\u914d\u3002\u628a\u5b83\u653e\u5728\u4f60\u8981\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5f00\u5934\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\nvar string_to_test = &quot;lets match at the beginning&quot;\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4ee5lets\u5f00\u5934\uff0c\u8fd4\u56detrue\nvar is_true = string_to_test.match(&quot;^lets&quot;);\n\n\u548c\u4f60\u671f\u5f85\u7684\u4e00\u6837\uff0c\u5982\u679c\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u4e0d\u662f\u5728\u5b57\u7b26\u4e32\u7684\u5f00\u5934\uff0c\u8fd9\u4e2a\u6d4b\u8bd5\u5c06\u8fd4\u56defalse:\n\n\/\/ \u6211\u4eec\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\nvar string_to_test = &quot;lets match at the beginning&quot;;\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4ee5match\u5f00\u5934\uff0c\u8fd4\u56defalse\nvar is_false = string_to_test.match(&quot;^match&quot;);\n<\/pre>\n<\/p>\n<p>\u7ee7\u7eed\u6d4b\u8bd5\u4e0b\u9762\u7684\uff1a<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_3 = function(){\n    var test_string = $('regex_3_value').get('value');\n    var regex_value = $('regex_3_match').get('value');\n    var regex_param = \"\";\n    if ($('regex_3_param').checked){\n        regex_param = \"i\";\n    }\n    var test_result = test_string.test(regex_value, regex_param);\n    if (test_result){\n        $('regex_3_result').set('html', \"matched\");\n    }\n    else {\n        $('regex_3_result').set('html', \"didn't match\");\n    }\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\uff1a<input id=\"regex_3_value\" class=\"t_text\" type=\"text\" value=\"lets match at the beginning\" \/><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_3_match\" class=\"t_text\" type=\"text\" value=\"^lets\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_3_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_3()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\u00a0<span id=\"regex_3_result\"><\/span>\n<\/p>\n<p><b>\u4f7f\u7528$\u5339\u914d\u5b57\u7b26\u4e32\u7684\u7ed3\u5c3e<\/b><\/p>\n<p>\u201c$\u201d\u8fd0\u7b97\u7b26\u7684\u529f\u80fd\u548c\u201c^\u201d\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u4f46\u662f\u6709\u4e24\u70b9\u4e0d\u4e00\u6837\uff1a<\/p>\n<ul style=\"list-style-type:decimal\">\n<li>\u5b83\u5339\u914d\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u7ed3\u5c3e\u800c\u4e0d\u662f\u5f00\u5934<\/li>\n<li>\u5b83\u653e\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u7ed3\u5c3e\u800c\u4e0d\u662f\u5f00\u5934<\/li>\n<\/ul>\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u5b83\u7684\u6240\u6709\u529f\u80fd\u548c\u4f60\u671f\u5f85\u7684\u4e00\u6837\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\nvar string_to_test = &quot;lets match at the end&quot;;\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4ee5end\u7ed3\u5c3e\uff0c\u8fd4\u56detrue\nvar is_true = string_to_test.match(&quot;end$&quot;);\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4ee5the\u7ed3\u5c3e\uff0c\u8fd4\u56defalse\nvar is_false = string_to_test.match(&quot;the$&quot;);\n<\/pre>\n<\/p>\n<p>\u901a\u8fc7\u8054\u5408\u4f7f\u7528\u8fd9\u4e24\u4e2a\u8fd0\u7b97\u7b26\uff0c\u4f60\u53ef\u4ee5\u505a\u4e00\u4e2a\u5f88\u5e72\u51c0\u7684\u6d4b\u8bd5\uff1a\u4f60\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u53ea\u5305\u542b\u4f60\u8981\u5339\u914d\u7684\u8868\u8fbe\u5f0f\u5185\u5bb9\u800c\u6ca1\u6709\u4efb\u4f55\u5176\u4ed6\u4e1c\u897f\u3002<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\nvar string_to_test = &quot;lets match everything&quot;;\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u5b8c\u5168\u548c&quot;lets match everything&quot;\u4e00\u6837\uff0c\u8fd4\u56detrue\nvar is_true = string_to_test.match(&quot;^lets match everything$&quot;);\n \n\/\/ \u6d4b\u8bd5\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u5b8c\u5168\u548c&quot;lets everything&quot;\u4e00\u6837\uff0c\u8fd4\u56defalse\nvar is_false = string_to_test.match(&quot;^lets everything$&quot;);\n<\/pre>\n<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_4 = function(){\n    var test_string = $('regex_4_value').get('value');\n    var regex_value = $('regex_4_match').get('value');\n    var regex_param = \"\";\n    if ($('regex_4_param').checked){\n        regex_param = \"i\";\n    }\n    var test_result = test_string.test(regex_value, regex_param);\n    if (test_result){\n        $('regex_4_result').set('html', \"matched\");\n    }\n    else {\n        $('regex_4_result').set('html', \"didn't match\");\n    }\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\uff1a<input id=\"regex_4_value\" class=\"t_text\" type=\"text\" value=\"lets match everything\" \/><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_4_match\" class=\"t_text\" type=\"text\" value=\"^lets match everything$\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_4_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_4()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\u00a0<span id=\"regex_4_result\"><\/span>\n<\/p>\n<p><b>\u5b57\u7b26\u96c6<\/b><\/p>\n<p>\u5b57\u7b26\u96c6\u662f\u53e6\u5916\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5de5\u5177\uff0c\u53ef\u4ee5\u5141\u8bb8\u4f60\u5339\u914d\u591a\u4e2a\u7279\u5b9a\u7684\u5b57\u7b26\uff08A\u6216\u8005Z\uff09\uff0c\u4ee5\u53ca\u4e00\u7cfb\u5217\u7684\u5b57\u7b26\uff08A\u5230Z\uff09\u3002\u636e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u4f60\u60f3\u6d4b\u8bd5\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5305\u542b\u5355\u8bcdmoo\u6216\u8005boo\uff0c\u901a\u8fc7\u5b57\u7b26\u96c6\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u65b9\u62ec\u53f7[]\u5185\u653e\u7f6e\u8fd9\u4e24\u4e2a\u5b57\u7b26\u6765\u5b9e\u73b0\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6d4b\u8bd5moo\u7528\u7684\u5b57\u7b26\u4e32\nvar first_string_to_test = &quot;cows go moo&quot;;\n \n\/\/ \u6d4b\u8bd5boo\u7528\u7684\u5b57\u7b26\u4e32\nvar second_string_to_test = &quot;ghosts go boo&quot;;\n \n\/\/ \u8fd9\u5339\u914d\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u800c\u4e0d\u5339\u914d\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\nvar returns_true = first_string_to_test.test(&quot;moo&quot;);\nvar returns_false = second_string_to_test(&quot;moo&quot;);\n \n\/\/ \u8fd9\u5339\u914d\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u800c\u4e0d\u5339\u914d\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\nreturns_false = first_string_to_test.test(&quot;boo&quot;);\nreturns_true = second_string_to_test.test(&quot;boo&quot;)\n \n\/\/ \u8fd9\u540c\u65f6\u5339\u914d\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\nreturns_true = first_string_to_test(&quot;[mb]oo&quot;);\nreturns_true = second_string_to_test(&quot;[mb]oo&quot;);\n<\/pre>\n<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_5 = function(){\n\tvar test_string_1 = $('regex_5_value_1').get('value');\n\tvar test_string_2 = $('regex_5_value_2').get('value');\n\tvar regex_value = $('regex_5_match').get('value');\n\tvar regex_param = \"\";\n\tif ($('regex_5_param').checked){\n\t\tregex_param = \"i\";\n\t}\n\tvar test_result_1 = test_string_1.test(regex_value, regex_param);\n\tif      (test_result_1){$('regex_5_result_1').set('html', \"matched\");}\n\telse {$('regex_5_result_1').set('html', \"didn't match\");}\n\tvar test_result_2 = test_string_2.test(regex_value, regex_param);\n\tif      (test_result_2){$('regex_5_result_2').set('html', \"matched\");}\n\telse {$('regex_5_result_2').set('html', \"didn't match\");}\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\u4e00\uff1a<input id=\"regex_5_value_1\" class=\"t_text\" type=\"text\" value=\"cows go moo\" \/>\u00a0<span id=\"regex_5_result_1\"><\/span><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\u4e8c\uff1a<input id=\"regex_5_value_2\" class=\"t_text\" type=\"text\" value=\"ghosts go boo\" \/>\u00a0<span id=\"regex_5_result_2\"><\/span><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_5_match\" class=\"t_text\" type=\"text\" value=\"[mb]oo\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_5_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_5()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\n<\/p>\n<p>\u4e3a\u4e86\u5339\u914d\u4e00\u7cfb\u5217\u7684\u5b57\u7b26\uff0c\u4f60\u53ef\u4ee5\u5355\u72ec\u62ff\u51fa\u8fd9\u4e00\u7cfb\u5217\u5b57\u7b26\u7684\u5f00\u5934\u4e00\u4e2a\u5b57\u7b26\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u7136\u540e\u628a\u5b83\u4eec\u7528\u4e00\u4e2a\u8fde\u63a5\u7b26\uff08-\uff09\u8fde\u63a5\u8d77\u6765\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5b9a\u4e49\u4e00\u7cfb\u5217\u7684\u6570\u5b57\u6216\u8005\u5b57\u7b26\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar string_to_test  = &quot; b or 3&quot;;\n\/\/ \u5339\u914da, b, c, \u6216\u8005d\uff0c\u8fd4\u56detrue\nstring_to_test.test(&quot;[a-d]&quot;);\n \n\/\/ \u5339\u914d1, 2, 3, 4, \u6216\u80055. \u8fd4\u56de true.\nstring_to_test.test(&quot;[1-5]&quot;);\n<\/pre>\n<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u5728\u591a\u4e2a\u5b57\u7b26\u96c6\u4e2d\u5339\u914d\uff0c\u4f60\u53ef\u4ee5\u628a\u4f60\u7684\u5b57\u7b26\u96c6\u653e\u5728\u4e00\u4e2a\u65b9\u62ec\u53f7[]\u4e2d\uff0c\u7136\u540e\u7528\u201c|\u201d\u8fd0\u7b97\u7b26\u9694\u5f00\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar string_to_test = &quot;b or 3&quot;;\n\/\/ \u5339\u914da\u5230d\u6216\u80051\u52305\uff0c\u8fd4\u56detrue\nstring_to_test.test([ [a-d] | [1-5] ]);\n<\/pre>\n<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_6 = function(){\n\tvar test_string_1 = $('regex_6_value_1').get('value');\n\tvar test_string_2 = $('regex_6_value_2').get('value');\n\tvar regex_value = $('regex_6_match').get('value');\n\tvar regex_param = \"\";\n\tif ($('regex_6_param').checked){\n\t\tregex_param = \"i\";\n\t}\n\tvar test_result_1 = test_string_1.test(regex_value, regex_param);\n\tif      (test_result_1){$('regex_6_result_1').set('html', \"matched\");}\n\telse {$('regex_6_result_1').set('html', \"didn't match\");}\n\tvar test_result_2 = test_string_2.test(regex_value, regex_param);\n\tif      (test_result_2){$('regex_6_result_2').set('html', \"matched\");}\n\telse {$('regex_6_result_2').set('html', \"didn't match\");}\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\u4e00\uff1a<input id=\"regex_6_value_1\" class=\"t_text\" type=\"text\" value=\"b\" \/>\u00a0<span id=\"regex_6_result_1\"><\/span><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\u4e8c\uff1a<input id=\"regex_6_value_2\" class=\"t_text\" type=\"text\" value=\"3\" \/>\u00a0<span id=\"regex_6_result_2\"><\/span><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_6_match\" class=\"t_text\" type=\"text\" value=\"[a-d]\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_6_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_6()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\n<\/p>\n<p><b>escapeRegExp()\u65b9\u6cd5<\/b><\/p>\n<p>\u5f53\u4f60\u770b\u5230\u6b63\u5219\u8868\u8fbe\u5f0f\u5efa\u7acb\u7684\u65b9\u6cd5\u65f6\uff0c\u4f60\u53ef\u80fd\u89c9\u5f97\u8981\u5339\u914d\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\u975e\u5e38\u7684\u56f0\u96be\u3002\u4e3e\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u5982\u679c\u4f60\u8981\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u201c[stuff-in-here]\u201d\u6216\u8005\u201c$300\u201d\u65f6\u600e\u4e48\u529e\uff1f\u4f60\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u5730\u5728\u6bcf\u4e2a\u4f60\u8981\u5ffd\u7565\u7684\u7279\u6b8a\u5b57\u7b26\u524d\u9762\u6dfb\u52a0\u2018\\\u2019\u6765\u5b9e\u73b0\u3002<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c\u6ce8\u610f[\u3001]\u3001-\u548c$\nvar string_to_match = &quot;[stuff-in-here] or $300&quot;;\n \n\/\/ \u4e0d\u6b63\u786e\u7684\u5339\u914d\u65b9\u5f0f\nstring_to_match.test(&quot;[stuff-in-here]&quot;);\nstring_to_match.test(&quot;$300&quot;);\n \n\/\/ \u6b63\u786e\u7684\u5339\u914d\u65b9\u5f0f\n\/\/ \u6ce8\u610f[\u3001]\u3001-\u548c$\u524d\u9762\u7684\\\nstring_to_match.test(&quot;\\[stuff\\-in\\-here\\]&quot;);\nstring_to_match.test(&quot;\\$300&quot;);\n<\/pre>\n<\/p>\n<p>\u8fd9\u5f80\u5f80\u662f\u5904\u7406\u6b63\u5219\u8868\u8fbe\u5f0f\u5934\u75db\u7684\u5730\u65b9\uff0c\u5c24\u5176\u662f\u4f60\u5bf9\u5b83\u4eec\u6ca1\u6709\u5b8c\u5168\u719f\u6089\u7684\u65f6\u5019\u3002\u4f5c\u4e3a\u53c2\u8003\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u9700\u8981\u8f6c\u4e49\u7684\u7279\u6b8a\u5b57\u7b26\u5305\u62ec\uff1a<\/p>\n<p>&#8211; . * + ? ^ $ { } ( ) | [ ] \/ \\<\/p>\n<p>\u5e78\u8fd0\u7684\u662f\uff0cMooTools\u63d0\u4f9b\u4e86escapeRegExp()\u51fd\u6570\uff0c\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u88ab\u6b63\u786e\u5730\u8f6c\u4e49\u3002\u8fd9\u662f\u53e6\u5916\u4e00\u4e2a\u5b57\u7b26\u4e32\u51fd\u6570\uff0c\u56e0\u6b64\u4f60\u53ea\u9700\u8981\u5728\u4f60\u5f00\u59cb\u67e5\u627e\u4e4b\u524d\uff0c\u5728\u4f60\u8981\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5b57\u7b26\u4e32\u4e0a\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u884c\u4e86\u3002<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u6211\u4eec\u8981\u8f6c\u4e49\u7684\u5b57\u7b26\u4e32\nvar unescaped_regex_string = &quot;[stuff-in-here]&quot;;\n \n\/\/ \u8f6c\u4e49\u8fd9\u4e2a\u5b57\u7b26\u4e32\nvar escaped_regex_string = unescaped_regex_string.escapeRegExp();\n \n\/\/ \u8f6c\u4e49\u540e\u7684\u5b57\u7b26\u4e32\u662f &quot;\\[stuff\\-in\\-here\\]&quot;\n<\/pre>\n<\/p>\n<p>\u6ce8\u610f\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u8981\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528\u7684\u4efb\u4f55\u7279\u6b8a\u5b57\u7b26\u90fd\u5fc5\u987b\u5728\u8f6c\u4e49\u4e4b\u540e\u518d\u6dfb\u52a0\u4e0a\u53bb\uff1a<\/p>\n<p><pre lang=\"javascript\">\n\/\/ \u9700\u8981\u8f6c\u4e49\u7684\u5b57\u7b26\u4e32\nvar unescaped_regex_string = &quot;[stuff-in-here]\u201c;\n\n\/\/ \u8f6c\u4e49\u8fd9\u4e2a\u5b57\u7b26\u4e32\uff0c\u4ece\u5f00\u5934\u5339\u914d\nvar escaped_regex_string = \u201c^\u201d + unescaped_regex_string.escapeRegExp();\n\n\/\/ escaped_regex_string\u73b0\u5728\u5c31\u662f\u201c^\\[stuff\\-in\\-here\\]\u201d\n<\/pre>\n<\/p>\n<p>\u7ee7\u7eed\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u6d4b\u8bd5\u4f7f\u7528escapeRegExp()\u548c\u4e0d\u4f7f\u7528\u7684\u533a\u522b\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar regex_demo = function(){\n    \/\/ \u83b7\u53d6\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\n    var test_string_1 = $('regex_7_value_1').get('value');\n \n    \/\/ \u83b7\u53d6\u8981\u4f7f\u7528\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\n    var regex_value = $('regex_7_match').get('value');\n \n    \/\/ \u68c0\u67e5\u6211\u4eec\u662f\u4e0d\u662f\u8981\u8f6c\u4e49\u6b63\u5219\u8868\u8fbe\u5f0f\n    if ($('regex_7_escape').checked){\n        \/\/ \u5982\u679c\u662f\u7684\uff0c\u6211\u4eec\u5219\u8fdb\u884c\u8f6c\u4e49\n        regex_value = regex_value.escapeRegExp();\n    }\n \n    \/\/ \u68c0\u67e5\u4e00\u4e0b\u6211\u4eec\u662f\u4e0d\u662f\u8981\u5ffd\u7565\u5927\u5c0f\u5199\n    var regex_param = &quot;&quot;;\n    if ($('regex_7_param').checked){\n        regex_param = &quot;i&quot;;\n    }\n \n    \/\/ \u8fd0\u884c\u6d4b\u8bd5\n    var test_result_1 = test_string_1.test(regex_value, regex_param);\n    if (test_result_1){\n        $('regex_7_result_1').set('html', &quot;matched&quot;);\n    }\n    else {\n        $('regex_7_result_1').set('html', &quot;didn't match&quot;);\n    }\n}\n<\/pre>\n<\/p>\n<p>\n<script type=\"text\/javascript\">\nvar regex_demo_7 = function(){\n    var test_string_1 = $('regex_7_value_1').get('value');\n    var regex_value = $('regex_7_match').get('value');\n    if ($('regex_7_escape').checked){\n        regex_value = regex_value.escapeRegExp();\n    }\n    var regex_param = \"\";\n    if ($('regex_7_param').checked){\n        regex_param = \"i\";\n    }\n    var test_result_1 = test_string_1.test(regex_value, regex_param);\n    if (test_result_1){\n        $('regex_7_result_1').set('html', \"matched\");\n    }\n    else {\n        $('regex_7_result_1').set('html', \"didn't match\");\n    }\n}\n<\/script><br \/>\n\u8981\u6d4b\u8bd5\u7684\u5b57\u7b26\u4e32\u4e00\uff1a<input id=\"regex_7_value_1\" class=\"t_text\" type=\"text\" value=\"[something] or $300\" \/>\u00a0<span id=\"regex_7_result_1\"><\/span><br \/>\n\u6b63\u5219\u8868\u8fbe\u5f0f      <input id=\"regex_7_match\" class=\"t_text\" type=\"text\" value=\"$300\" \/><br \/>\n\u5bf9\u6b63\u5219\u8fdb\u884c\u8f6c\u4e49  <input id=\"regex_7_escape\" type=\"checkbox\" \/><br \/>\n\u5ffd\u7565\u5927\u5c0f\u5199      <input id=\"regex_7_param\" type=\"checkbox\" \/><br \/>\n<input onclick=\"regex_demo_7()\" type=\"button\" value=\"\u8fd0\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\" \/>\n<\/p>\n<p><i>\u8bb0\u4f4f\uff0c\u4f60\u53ef\u80fd\u56e0\u4e3a\u4f7f\u7528\u4e86\u6ca1\u6709\u8f6c\u4e49\u7684\u7279\u6b8a\u5b57\u7b26\u800c\u4f7f\u6f14\u793a\u4f8b\u5b50\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u56e0\u6b64\u5f53\u793a\u4f8b\u4e0d\u80fd\u8fd0\u884c\u7684\u65f6\u5019\u8bf7\u4e0d\u8981\u611f\u5230\u5947\u602a\uff0c\u56e0\u4e3a\u4f60\u4e00\u76f4\u90fd\u5728\u73a9\u8fd9\u4e9b\u4e1c\u897f\u3002<\/i><\/p>\n<h3>\u66f4\u591a\u5b66\u4e60<\/h3>\n<p><b><a href=\"http:\/\/www.consideropen.com\/downloads\/30days_of_moo\/mootorial_day13_regexes.zip\" target=\"_blank\" title=\"\u4e0b\u8f7d\u4e00\u4e2a\u5305\u542b\u4f60\u5f00\u59cb\u6240\u9700\u8981\u7684\u6240\u6709\u4e1c\u897f\u7684zip\u5305\">\u4e0b\u8f7d\u4e00\u4e2a\u5305\u542b\u4f60\u5f00\u59cb\u6240\u9700\u8981\u7684\u6240\u6709\u4e1c\u897f\u7684zip\u5305<\/a><\/b><\/p>\n<p><a href=\"http:\/\/www.regular-expressions.info\/\" target=\"_blank\" title=\"Regular-Expressions.info\">Regular-Expressions.info<\/a>\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u53c2\u8003\u548c\u5b66\u4e60\u7684\u5730\u65b9\u2014\u2014\u4e00\u4e2a\u503c\u5f97\u82b1\u4e00\u4e9b\u65f6\u95f4\u6d4f\u89c8\u7684\u7f51\u7ad9\u3002\u5bf9\u4e8e\u90a3\u4e9b\u719f\u6089Perl\u6216\u8005\u719f\u6089\u5404\u79cd\u8bed\u8a00\u5dee\u5f02\u7684\u4eba\uff0c<a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\/#77-BasicRegularExpressions\" target=\"_blank\" title=\"Robert\u7684Perl\u6559\u7a0b\">Robert\u7684Perl\u6559\u7a0b<\/a>\u4e2d\u7684\u5173\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\u8fd9\u4e00\u8282\u5219\u5bf9\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u89e3\u91ca\u5f97\u975e\u5e38\u7684\u597d\u3002\u540c\u6837\uff0cStephen Ramsay\u5df2\u7ecf\u5199\u4e86\u4e00\u4e2a\u5173\u4e8e<a href=\"http:\/\/etext.lib.virginia.edu\/services\/helpsheets\/unix\/regex.html\" target=\"_blank\" title=\"Unix\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6559\u7a0b\">Unix\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6559\u7a0b<\/a>\uff0c\u7528\u4e00\u79cd\u975e\u5e38\u6e05\u695a\u548c\u76f4\u63a5\u4e86\u5f53\u7684\u65b9\u5f0f\u8bb2\u89e3\u4e86\u5176\u4e2d\u7684\u4e00\u4e9b\u6982\u5ff5\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u4e2a\u4e0d\u9519\u7684\u5730\u65b9\u662f<a href=\"http:\/\/regexlib.com\/\" target=\"_blank\" title=\"\u6b63\u5219\u8868\u8fbe\u5f0f\u5e93\">\u6b63\u5219\u8868\u8fbe\u5f0f\u5e93<\/a>\uff0c\u5b83\u4eec\u6709\u6570\u4e0d\u6e05\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4f8b\u5b50\u6765\u5b8c\u6210\u5404\u79cd\u5404\u6837\u7684\u5e38\u89c1\u4efb\u52a1\u3002\u6700\u540e\uff0c\u5982\u679c\u4f60\u6709\u52c7\u6c14\uff0c\u4f60\u5e94\u8be5\u82b1\u4e00\u4e9b\u65f6\u95f4\u6765\u770b\u4e00\u4e0bMozilla\u7684<a href=\"http:\/\/developer.mozilla.org\/en\/Core_JavaScript_1.5_Guide\/Regular_Expressions\" target=\"_blank\" title=\"JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f\u53c2\u8003\u624b\u518c\">JavaScript\u6b63\u5219\u8868\u8fbe\u5f0f\u53c2\u8003\u624b\u518c<\/a>\u3002\u8fd9\u53ef\u80fd\u975e\u5e38\u7684\u591a\uff0c\u4f46\u662f\u6781\u5176\u6709\u7528\u3002\u5982\u679c\u4f60\u60f3\u770b\u4e00\u4e0bMooTools\u8fd9\u8fb9\u5173\u4e8e\u6b63\u5219\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u770b\u4e00\u4e0b<a href=\"http:\/\/docs.mootools.net\/Native\/String#String:test\" target=\"_blank\" title=\"test()\u51fd\u6570\u7684\u6587\u6863\">test()\u51fd\u6570\u7684\u6587\u6863<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1a30 Days of Mootools 1.2 Tutorials &#8211; Day 13 &#8211; Regular Expressions MooTools\u548c\u6b63\u5219\u8868\u8fbe\u5f0f \u8bf7\u5c0a\u91cd\u4e2a\u4eba\u52b3\u52a8\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttp:\/\/fdream.net\uff0c \u8bd1\u8005\uff1aFdream \u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u51c6\u5907\u597d\u5f00\u59cb\u8fd9\u4e00\u8bb2\uff0c\u6211\u5efa\u8bae\u4f60\u5148\u770b\u8fd9\u4e00\u7cfb\u5217\u7684\u6559\u7a0b\u7684\u524d\u9762\u4e00\u90e8\u5206\uff0c\u8fd9\u91cc\u662f\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b\u3002 \u4eca\u5929\u6211\u4eec\u5c06\u5148\u7b80\u8981\u5730\u770b\u4e00\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u518d\u770b\u4e00\u4e0bMooTools\u63d0\u4f9b\u7684\u4e00\u4e9b\u8ba9\u6b63\u5219\u8868\u8fbe\u5f0f\u66f4\u5bb9\u6613\u4f7f\u7528\u7684\u529f\u80fd\u3002\u5982\u679c\u4f60\u8fd8\u4e0d\u719f\u6089\u600e\u4e48\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff08regular expression\uff08regex\uff09\uff09\uff0c\u6211\u5f3a\u70c8\u5efa\u8bae\u4f60\u82b1\u4e00\u5b9a\u91cf\u7684\u65f6\u95f4\u597d\u597d\u770b\u4e00\u4e0b\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u7684\u4e00\u4e9b\u94fe\u63a5\uff0c\u5c24\u5176\u662f\u6587\u7ae0\u7ed3\u5c3e\u201c\u66f4\u591a\u5b66\u4e60\u201d\u90e8\u5206\u7684\u94fe\u63a5\u3002\u6211\u4eec\u4eca\u5929\u53ea\u662f\u8bb2\u4e00\u8bb2\u6b63\u5219\u8868\u8fbe\u5f0f\u6700\u57fa\u672c\u7684\u7528\u6cd5\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u80fd\u505a\u7684\u8fdc\u8fdc\u8d85\u8fc7\u6211\u4eec\u4eca\u5929\u6240\u8bb2\u7684\u5185\u5bb9\u3002 \u57fa\u672c\u7528\u6cd5 test()\u65b9\u6cd5 \u5b83\u7684\u7b80\u5355\u5728\u4e8e\uff0c\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u662f\u4e00\u4e2a\u4f60\u60f3\u8981\u5339\u914d\u7684\u7b80\u5355\u5b57\u7b26\u4e32\u3002\u5c3d\u7ba1JavaScript\u672c\u8eab\u5df2\u7ecf\u4e3aRegExp\u5bf9\u8c61\u63d0\u4f9b\u4e86\u5b83\u81ea\u5df1\u7684test()\u65b9\u6cd5\uff0cMooTools\u7684test()\u65b9\u6cd5\u66f4\u597d\u7528\u4e00\u4e9b\uff0c\u5728JavaScript\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4e5f\u66f4\u8f7b\u677e\u4e00\u4e9b\u3002 \u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0btest()\u65b9\u6cd5\u6700\u7b80\u5355\u7684\u7528\u6cd5\uff0c\u5728\u4e00\u4e2a\u5927\u7684\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\uff1a \/\/ \u6211\u4eec\u8981\u5728\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e var string_to_test = &quot;Match anything in here&quot;; \/\/ \u6211\u4eec\u8981\u67e5\u627e\u7684\u6b63\u5219\u8868\u8fbe\u5f0f var regular_expression = &quot;anything&quot;; \/\/ \u5e94\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8fd4\u56detrue\u6216\u8005false var result = string_to_test.test(regular_expression); \/\/ result\u73b0\u5728\u4e3atrue \u8fd9\u548ccontains()\u51fd\u6570\u7684\u884c\u4e3a\u57fa\u672c\u7c7b\u4f3c\uff0c\u4e0d\u8fc7contains\u662f\u6309\u7167\u5b8c\u6574\u7684\u5355\u8bcd\u67e5\u627e\uff0c\u800c\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u4efb\u4f55\u5b83\u51fa\u73b0\u7684\u5730\u65b9\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5728\u4e0b\u9762\u7684\u8fd9\u4e2a\u5b9e\u4f8b\u4e2d\uff0ccontains()\u65b9\u6cd5\u5c06\u4e0d\u8fd4\u56detrue\uff0c\u800ctest()\u65b9\u6cd5\u5c06\u8fd4\u56detrue\u3002\uff08Fdream\u6ce8\uff1a\u7ecftaoyu3781212\u7684\u63d0\u9192\uff0c\u8fd9\u4e2a\u8bf4\u6cd5\u662f\u4e0d\u6b63\u786e\u7684\u3002\u5b9e\u9645\u4e0a\uff0ccontains()\u65b9\u6cd5\u53ef\u4ee5\u6307\u5b9a\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u67e5\u627e\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u662f\u5206\u9694\u5b57\u7b26\u4e32\uff0c\u53ea\u6709\u5f53\u6307\u5b9a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u65f6\uff0ccontains()\u65b9\u6cd5\u624d\u4f1a\u8fd4\u56defalse\uff0c\u8fd9\u4e2a\u5b9e\u9645\u4e0a\u5c31\u662farray\u7684contains()\u65b9\u6cd5\u3002\uff09 var string_to_match = &quot;anything else&quot;; \/\/ \u8fd4\u56detrue string_to_match.contains(&#8216;nything&#8217;) &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[120,104,328,123],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-coding","tag-AJAX","tag-JavaScript","tag-mootools","tag-123"],"views":12707,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=622"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/622\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}