{"id":1547,"date":"2020-09-29T16:17:45","date_gmt":"2020-09-29T08:17:45","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=1547"},"modified":"2021-02-19T11:04:09","modified_gmt":"2021-02-19T03:04:09","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e4%b8%ad%e5%8e%9f%e5%ad%90%e7%bb%84%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2020\/09\/29\/1617451547.html","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u539f\u5b50\u7ec4\u7684\u57fa\u672c\u4f7f\u7528"},"content":{"rendered":"<h3>\u4ec0\u4e48\u662f\u539f\u5b50\u7ec4<\/h3>\n<p>\u7b80\u5355\u4e00\u70b9\u8bb2\uff0c\u539f\u5b50\u7ec4\u5c31\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u5c0f\u62ec\u53f7()\u53ca\u6240\u5305\u62ec\u7684\u5185\u5bb9<\/p>\n<h4>\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b<\/h4>\n<pre><code class=\"language-javascript line-numbers\">let date = '\u4eca\u5929\u662f2020-09\/29';\n\/\/ \u65e5\u671f\u5206\u9694\u7b26\u6709\/\u6216-\uff0c\u5982\u662f\u5206\u5f00\u5199\uff0c\u4f1a\u5339\u914d\u51fa\u524d\u540e\u4e0d\u4e00\u81f4\u7684\u6570\u636e\uff0c\u6bd4\u59822020-09\/29\nlet reg = \/\\d{4}[\\\/\\-]\\d{2}[\\\/\\-]\\d{2}\/g;\nconsole.log(date.match(reg));\n\/\/ \u4fee\u6b63\u4e3a\u524d\u540e\u4fdd\u6301\u4e00\u81f4\uff0c\u540e\u9762\u7684\u5206\u9694\u7b26\u53ef\u4f7f\u7528\u524d\u9762\u7684\u539f\u5b50\u7ec4\uff0c\u76f4\u63a5\u5199\u5e8f\u53f7\u5373\u53ef\uff0c\u56e0\u4e3a\u662f\u7b2c1\u4e2a\uff0c\u6240\u4ee5\u8f6c\u4e491\n\/\/ \u6b64\u65f6\u5982\u679c\u662f2020-09\/29\u5c31\u5339\u914d\u4e0d\u6210\u529f\u4e86\nreg = \/\\d{4}([\\\/\\-])\\d{2}\\1\\d{2}\/g;\nconsole.log(date.match(reg));\n<\/code><\/pre>\n<h3>\u83b7\u53d6\u539f\u5b50\u7ec4\u6570\u636e<\/h3>\n<p>\u5982\u679c\u6709\u5305\u62ec\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u7b26\u4e32<code>\u5317\u4eac\uff1a010-85990021, \u4e0a\u6d77\uff1a020-69323342<\/code>\uff0c\u73b0\u5728\u9700\u8981\u5c06\u683c\u5f0f\u8f6c\u6362\u6210<code>(xxx)xxxxxxx<\/code>\u8be5\u5982\u4f55\u5904\u7406\u5462\uff1f<\/p>\n<ol>\n<li>\u5148\u5339\u914d\u51fa\u7535\u8bdd\u53f7\u7801\uff0c\u8fd9\u4e2a\u7b80\u5355\u6b63\u5219<code>\/\\d{3,4}-\\d{7,8}\/g<\/code>\u5373\u53ef\u5339\u914d\u52302\u4e2a\u7535\u8bdd\u53f7\u7801\uff1b<\/li>\n<li>\u53d6\u51fa\u533a\u53f7\u6570\u636e\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u5c06\u533a\u53f7\u5355\u72ec\u5212\u5206\u6210\u4e00\u4e2a\u539f\u5b50\u7ec4\uff0c\u4fee\u6539\u540e\u7684\u6b63\u5219\u4e3a\uff1a<code>\/(\\d{3,4})-\\d{7,8}\/g<\/code>\uff1b<\/li>\n<\/ol>\n<pre><code class=\"language-javascript line-numbers\">let tel = '\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342';\n\/\/ \u83b7\u53d6\u7535\u8bdd\u53f7\u7801\u7684\u6b63\u5219\u5982\u4e0b\uff1a\nlet reg = \/\\d{3}-\\d{7,8}\/g;\n\/**\n * \u5339\u914d\u7ed3\u679c\u4e3a\uff1a[ '010-85990021', '020-69323342' ]\n *\/\nconsole.log(tel.match(reg));\n\n\/\/ \u5c06\u533a\u53f7\u5355\u72ec\u5212\u5206\u4e00\u4e2a\u539f\u5b50\u7ec4\uff0c\u65b9\u4fbf\u83b7\u53d6\u6570\u636e\nreg = \/(\\d{3,4})-\\d{7,8}\/g\ntel.replace(reg, function(substr, ...args){\n    console.log(args);\n})\n<\/code><\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre><code class=\"language-markdown line-numbers\">[ '010-85990021', '020-69323342' ]\n[ '010', 3, '\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342' ]\n[ '020', 20, '\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342' ]\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u5982\u679c\u6b64\u65f6\u5c06\u6574\u4e2a\u6b63\u5219\u5339\u914d\u7684\u5185\u5bb9\u5206\u522b\u5206\u914d\u52303\u4e2a\u539f\u5b50\u7ec4\u4e2d\uff0c\u5c31\u65b9\u4fbf\u540e\u7eed\u7684\u6570\u636e\u5904\u7406\u4e86\uff0c\u4fee\u6b63\u4e3a\uff1a<code>\/(\\d{3,4})(-)(\\d{7,8})\/g<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-markdown line-numbers\">[ '010', '-', '85990021', 3, '\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342' ]\n[ '020', '-', '69323342', 20, '\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342' ]\n<\/code><\/pre>\n<ol start=\"4\">\n<li>\u73b0\u5728\u5b8c\u5168\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66ff\u6362\u539f\u5b57\u7b26\u4e32\u4e86\uff0c\u6bd4\u5982\u5728replace\u65b9\u6cd5\u7684\u56de\u8c03\u51fd\u6570\u4e2d\u8fd4\u56de<code>(${args[0]})-${args[2]}<\/code>\u5373\u53ef\u5f97\u5230<code>\u5317\u4eac\uff1a(010)-85990021\uff0c \u4e0a\u6d77\uff1a(020)-69323342<\/code><\/li>\n<\/ol>\n<h3>\u547d\u540d\u539f\u5b50\u7ec4<\/h3>\n<p>\u4ee5\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u4e3a\u4f8b\uff1a<code>example@domain.com<\/code>\uff0c\u5982\u679c\u9700\u8981\u5bf9\u7528\u6237\u540d\u548c\u57df\u540d\u8fdb\u884c\u533a\u5206\uff0c\u7b80\u5355\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4e3a\uff1a<code>\/.+@.+\/<\/code>\u3002<\/p>\n<p>\u73b0\u5728\u4ee5\u7528\u6237\u540d\u548c\u57df\u540d\u5206\u522b\u5212\u5165\u539f\u5b50\u7ec4\u4e2d\uff0c\u547d\u540d\u683c\u5f0f\u4e3a<code>?&lt;xxxx&gt;<\/code>\uff0c\u6b63\u5219\u4fee\u6b63\u4e3a\uff1a<code>\/(?&lt;username&gt;.+)@(?&lt;domain&gt;.+)\/<\/code><\/p>\n<p>\u4f7f\u7528\u5b57\u7b26\u4e32\u7684<code>match<\/code>\u65b9\u6cd5\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-json line-numbers\">[\n  'example@domain.com',\n  'example',\n  'domain.com',\n  index: 0,\n  input: 'example@domain.com',\n  groups: [Object: null prototype] {\n    username: 'example',\n    domain: 'domain.com'\n  }\n]\n<\/code><\/pre>\n<h3>\u6b63\u5219\u66ff\u6362\u4e2d\u5339\u914d\u7ed3\u679c\u53d8\u91cf<\/h3>\n<ul>\n<li><strong>$`<\/strong> \u8868\u793a\u5339\u914d\u9879\u524d\u9762\u7684\u5185\u5bb9<\/li>\n<li><strong>$&amp;<\/strong> \u8868\u793a\u5339\u914d\u9879\u81ea\u8eab<\/li>\n<li><strong>$&#8217;<\/strong> \u8868\u793a\u5339\u914d\u9879\u540e\u9762\u7684\u5185\u5bb9<\/li>\n<\/ul>\n<pre><code class=\"language-javascript line-numbers\">let str = '123abc456';\n\/\/ \u5339\u914d\u7ed3\u679cabc\uff0cabc\u524d\u9762\u4e3a123\uff0c\u540e\u9762\u4e3a456\n\/\/ \u66ff\u6362\u7ed3\u679c\u4e3a123-123-abc-456-456\nstr.replace(\/[A-z]+\/, '-$`-$&amp;-$\\'-')\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u539f\u5b50\u7ec4 \u7b80\u5355\u4e00\u70b9\u8bb2\uff0c\u539f\u5b50\u7ec4\u5c31\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u5c0f\u62ec\u53f7()\u53ca\u6240\u5305\u62ec\u7684\u5185\u5bb9 \u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b let date = &#8216;\u4eca\u5929\u662f2020-09\/29&#8217;; \/\/ \u65e5\u671f\u5206\u9694\u7b26\u6709\/\u6216-\uff0c\u5982\u662f\u5206\u5f00\u5199\uff0c\u4f1a\u5339\u914d\u51fa\u524d\u540e\u4e0d\u4e00\u81f4\u7684\u6570\u636e\uff0c\u6bd4\u59822020-09\/29 let reg = \/\\d{4}[\\\/\\-]\\d{2}[\\\/\\-]\\d{2}\/g; console.log(date.match(reg)); \/\/ \u4fee\u6b63\u4e3a\u524d\u540e\u4fdd\u6301\u4e00\u81f4\uff0c\u540e\u9762\u7684\u5206\u9694\u7b26\u53ef\u4f7f\u7528\u524d\u9762\u7684\u539f\u5b50\u7ec4\uff0c\u76f4\u63a5\u5199\u5e8f\u53f7\u5373\u53ef\uff0c\u56e0\u4e3a\u662f\u7b2c1\u4e2a\uff0c\u6240\u4ee5\u8f6c\u4e491 \/\/ \u6b64\u65f6\u5982\u679c\u662f2020-09\/29\u5c31\u5339\u914d\u4e0d\u6210\u529f\u4e86 reg = \/\\d{4}([\\\/\\-])\\d{2}\\1\\d{2}\/g; console.log(date.match(reg)); \u83b7\u53d6\u539f\u5b50\u7ec4\u6570\u636e \u5982\u679c\u6709\u5305\u62ec\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u7b26\u4e32\u5317\u4eac\uff1a010-85990021, \u4e0a\u6d77\uff1a020-69323342\uff0c\u73b0\u5728\u9700\u8981\u5c06\u683c\u5f0f\u8f6c\u6362\u6210(xxx)xxxxxxx\u8be5\u5982\u4f55\u5904\u7406\u5462\uff1f \u5148\u5339\u914d\u51fa\u7535\u8bdd\u53f7\u7801\uff0c\u8fd9\u4e2a\u7b80\u5355\u6b63\u5219\/\\d{3,4}-\\d{7,8}\/g\u5373\u53ef\u5339\u914d\u52302\u4e2a\u7535\u8bdd\u53f7\u7801\uff1b \u53d6\u51fa\u533a\u53f7\u6570\u636e\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u5c06\u533a\u53f7\u5355\u72ec\u5212\u5206\u6210\u4e00\u4e2a\u539f\u5b50\u7ec4\uff0c\u4fee\u6539\u540e\u7684\u6b63\u5219\u4e3a\uff1a\/(\\d{3,4})-\\d{7,8}\/g\uff1b let tel = &#8216;\u5317\u4eac\uff1a010-85990021\uff0c \u4e0a\u6d77\uff1a020-69323342&#8217;; \/\/ \u83b7\u53d6\u7535\u8bdd\u53f7\u7801\u7684\u6b63\u5219\u5982\u4e0b\uff1a let reg = \/\\d{3}-\\d{7,8}\/g; \/** * \u5339\u914d\u7ed3\u679c\u4e3a\uff1a[ &#8216;010-85990021&#8217;, &#8216;020-69323342&#8217; ] *\/ console.log(tel.match(reg)); \/\/ \u5c06\u533a\u53f7\u5355\u72ec\u5212\u5206\u4e00\u4e2a\u539f\u5b50\u7ec4\uff0c\u65b9\u4fbf\u83b7\u53d6\u6570\u636e reg = \/(\\d{3,4})-\\d{7,8}\/g tel.replace(reg, function(substr, &#8230;args){ console.log(args); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,35,28,11],"tags":[53,238,237,240,239],"class_list":["post-1547","post","type-post","status-publish","format-standard","hentry","category-android","category-java","category-javascript","category-project","tag-javascript","tag-regexp","tag-237","tag-240","tag-239"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1547"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1547\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}