{"id":5244,"date":"2023-01-05T12:16:51","date_gmt":"2023-01-05T04:16:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5244"},"modified":"2023-01-05T12:16:51","modified_gmt":"2023-01-05T04:16:51","slug":"%e4%ba%86%e8%a7%a3typescript%e5%ad%97%e4%b8%b2%e7%9a%84%e6%b1%82%e6%98%af%e5%90%a6%e5%8c%b9%e9%85%8d%e6%8c%87%e5%ae%9a%e6%ad%a3%e5%89%87%e8%a1%a8%e9%81%94%e5%bc%8fmatch","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e5%ad%97%e4%b8%b2%e7%9a%84%e6%b1%82%e6%98%af%e5%90%a6%e5%8c%b9%e9%85%8d%e6%8c%87%e5%ae%9a%e6%ad%a3%e5%89%87%e8%a1%a8%e9%81%94%e5%bc%8fmatch\/","title":{"rendered":"\u4e86\u89e3TypeScript\u5b57\u4e32\u7684\u6c42\u662f\u5426\u5339\u914d\u6307\u5b9a\u6b63\u5247\u8868\u9054\u5f0f(match)"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u6b63\u5247\u8868\u9054\u5f0f, match\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684\u6c42\u662f\u5426\u5339\u914d\u6307\u5b9a\u6b63\u5247\u8868\u9054\u5f0f(match)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709 JavaScript \u7684\u6240\u6709\u529f\u80fd\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86\u984d\u5916\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\u3002TypeScript \u652f\u63f4\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6a21\u5f0f\u3002<\/p>\n<h2>TypeScript \u4e2d\u7684 match() \u65b9\u6cd5<\/h2>\n<p>TypeScript \u4e2d\u7684 match() \u65b9\u6cd5\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\u3002\u5b83\u6703\u56de\u50b3\u4e00\u500b\u9663\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6240\u6709\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f\u7684\u5b57\u4e32\u3002\u5982\u679c\u6c92\u6709\u7b26\u5408\u7684\u5b57\u4e32\uff0c\u5247\u6703\u56de\u50b3 null\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet str = \"Hello World!\";\nlet regex = \/Hello\/;\nlet result = str.match(regex);\n\nconsole.log(result); \/\/ [\"Hello\"]\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 match() \u65b9\u6cd5\u6aa2\u67e5\u5b57\u4e32 &#8220;Hello World!&#8221; \u662f\u5426\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f \/Hello\/\u3002\u7d50\u679c\u70ba [&#8220;Hello&#8221;]\uff0c\u8868\u793a\u5b57\u4e32 &#8220;Hello World!&#8221; \u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f \/Hello\/\u3002<\/p>\n<h2>TypeScript \u4e2d\u7684 test() \u65b9\u6cd5<\/h2>\n<p>TypeScript \u4e2d\u7684 test() \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\u3002\u5b83\u6703\u56de\u50b3\u4e00\u500b\u5e03\u6797\u503c\uff0c\u8868\u793a\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet str = \"Hello World!\";\nlet regex = \/Hello\/;\nlet result = regex.test(str);\n\nconsole.log(result); \/\/ true\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 test() \u65b9\u6cd5\u6aa2\u67e5\u5b57\u4e32 &#8220;Hello World!&#8221; \u662f\u5426\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f \/Hello\/\u3002\u7d50\u679c\u70ba true\uff0c\u8868\u793a\u5b57\u4e32 &#8220;Hello World!&#8221; \u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f \/Hello\/\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u652f\u63f4\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6a21\u5f0f\u3002TypeScript \u4e2d\u7684 match() \u65b9\u6cd5\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u5b83\u6703\u56de\u50b3\u4e00\u500b\u9663\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6240\u6709\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f\u7684\u5b57\u4e32\u3002TypeScript \u4e2d\u7684 test() \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u5b83\u6703\u56de\u50b3\u4e00\u500b\u5e03\u6797\u503c\uff0c\u8868\u793a\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6b63\u5247\u8868\u9054\u5f0f\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u66f4\u591a\u8cc7\u8a0a<\/h2>\n<p>\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u95dc\u65bc TypeScript \u4e2d\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u8acb\u53c3\u8003 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/regular-expressions.html\" style=\"color: #0099cc;\" target=\"_blank\" rel=\"noopener\">TypeScript \u5b98\u65b9\u6587\u4ef6<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3TypeScript\u5b57\u4e32\u7684\u6c42\u662f\u5426\u5339\u914d\u6307\u5b9a\u6b63\u5247\u8868\u9054\u5f0f(match)\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScript\u4e2d\u7684match()\u51fd\u6578\u4f86\u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u63d0\u9ad8\u7a0b\u5f0f\u78bc\u7684\u53ef\u8b80\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5244","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1mA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5244"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5244\/revisions"}],"predecessor-version":[{"id":5245,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5244\/revisions\/5245"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}