{"id":323,"date":"2009-04-17T13:34:00","date_gmt":"2009-04-17T05:34:00","guid":{"rendered":""},"modified":"2013-11-29T11:47:08","modified_gmt":"2013-11-29T03:47:08","slug":"javascript%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8fexec%e5%92%8ctest%e6%96%b9%e6%b3%95%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/323.html","title":{"rendered":"JavaScript\u6b63\u5219\u8868\u8fbe\u5f0fexec\u548ctest\u65b9\u6cd5\u5b9e\u4f8b"},"content":{"rendered":"<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script LANGUAGE=&quot;javascript&quot;&gt;\r\nvar u=&quot;http:\/\/msdn.microsoft.com:80\/scripting\/default.htm&quot;;\r\nvar s=\/(\\w+):\\\/\\\/(&#x5B;^\/:]+)(:\\d*)?(&#x5B;^# ]*)\/;\r\nvar a=s.exec(u);\r\nfor(i=1;i&lt;a.length;i++){\r\nalert(a&#x5B;i]);\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>\u5c06\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u5e94\u7528\u4e8e\u4e0a\u9762\u6240\u793a\u7684URL\u540e\uff0c\u5b50\u5339\u914d\u5305\u542b\u4e0b\u8ff0\u5185\u5bb9\uff1a<br \/>\na[1] \u5305\u542b &#8220;http&#8221;<br \/>\na[2] \u5305\u542b &#8220;msdn.microsoft.com&#8221;<br \/>\na[3] \u5305\u542b &#8220;:80&#8221;<br \/>\na[4] \u5305\u542b &#8220;\/scripting\/default.htm&#8221;<br \/>\n(\u4e5f\u53ef\u4ee5\u7528RegExp.$1\u3001RegExp.$2\u3001RegExp.$3\u3001RegExp.$4\u53d6\u503c)<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script LANGUAGE=&quot;javascript&quot;&gt;\r\nfunction checkMobile( s )\u2026{\r\nvar regu =\/^&#x5B;1]&#x5B;3]&#x5B;0-9]\u2026{9}$\/;\r\nvar re = new RegExp(regu);\r\nreturn re.test(s);\r\n}\r\ncheckMobile(\u201913909910000\u2032);\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>\u7528\u9014\uff1a\u68c0\u67e5\u8f93\u5165\u624b\u673a\u53f7\u7801\u662f\u5426\u6b63\u786e,\u5982\u679c\u901a\u8fc7\u9a8c\u8bc1\u8fd4\u56detrue,\u5426\u5219\u8fd4\u56defalse<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u521b\u5efa\uff0c\u67092\u79cd\u529e\u6cd5\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar my_regex=\/&#x5B;a-z]+\/g;\r\nvar my_regex=new (\u201d&#x5B;a-z]+\u201d,&quot;g\u201d);\r\n<\/pre>\n<p>\u65b9\u6cd5<br \/>\nexec(string)\uff1a \u5bf9string\u8fdb\u884c\u6b63\u5219\u5904\u7406,\u5e76\u8fd4\u56de\u5339\u914d\u7ed3\u679c.<br \/>\nexec\u65b9\u6cd5\u8fd4\u56de\u7684\u6570\u7ec4\u67093\u4e2a\u5c5e\u6027\uff0c\u5206\u522b\u662finput\u3001index\u548clastIndex \u3002<br \/>\n1 input \u5c5e\u6027\u662f\u6574\u4e2a\u88ab\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n2 index\u5c5e\u6027\u662f\u6307\u5339\u914d\u5728\u6574\u4e2a\u88ab\u641c\u7d22\u5b57\u7b26\u4e32\u4e2d\u7684\u4f4d\u7f6e\u3002<br \/>\n3 lastIndex \u5c5e\u6027\u662f\u6307\u5339\u914d\u7684\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\u4f4d\u7f6e\u3002<\/p>\n<p>test(string)\uff1a \u6d4b\u8bd5string\u662f\u5426\u542b\u6709\u5339\u914d\u7ed3\u679c<\/p>\n<p>\u5b57\u7b26\u4e32\u5bf9\u8c61\u4e2d\u7684\u6b63\u5219<br \/>\n\u65b9\u6cd5<br \/>\nmatch(pattern) \uff1a\u6839\u636epattern\u8fdb\u884c\u6b63\u5219\u5339\u914d,\u5982\u679c\u5339\u914d\u5230,\u8fd4\u56de\u5339\u914d\u7ed3\u679c,\u5982\u5339\u914d\u4e0d\u5230\u8fd4\u56denull<br \/>\nsearch(pattern) \uff1a\u6839\u636epattern\u8fdb\u884c\u6b63\u5219\u5339\u914d,\u5982\u679c\u5339\u914d\u5230\u4e00\u4e2a\u7ed3\u679c,\u5219\u8fd4\u56de\u5b83\u7684\u7d22\u5f15\u6570;\u5426\u5219\u8fd4\u56de-1<br \/>\nreplace(pattern,replacement) \uff1a\u6839\u636epattern\u8fdb\u884c\u6b63\u5219\u5339\u914d,\u628a\u5339\u914d\u7ed3\u679c\u66ff\u6362\u4e3areplacement<br \/>\nsplit(pattern) \uff1a\u6839\u636epattern\u8fdb\u884c\u6b63\u5219\u5206\u5272,\u8fd4\u56de\u4e00\u4e2a\u5206\u5272\u7684\u6570\u7ec4<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;script LANGUAGE=&quot;javascript&quot;&gt; var u=&#038;q [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-323","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=323"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/323\/revisions"}],"predecessor-version":[{"id":5304,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/323\/revisions\/5304"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}