{"id":10499,"date":"2022-08-21T15:27:33","date_gmt":"2022-08-21T07:27:33","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10499"},"modified":"2022-08-21T15:28:12","modified_gmt":"2022-08-21T07:28:12","slug":"js-replaceall-matchall","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/08\/js-replaceall-matchall\/","title":{"rendered":"JS replaceAll \u548c matchAll \u4f7f\u7528\u6307\u5357\u4e0d\u6307\u5317"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10499\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10499<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202208-replaceall-matchall.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/jsall-cover.png\" width=\"480\" height=\"308\" alt=\"\u5c01\u9762\u56fe-\u7eb8\u98de\u673a\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u5148\u8bf4\u4e0b replaceAll<\/h3>\n<p><code>replaceAll<\/code> \u8fd9\u4e2a API \u662f\u6700\u8fd1\u4e00\u4e24\u5e74\u65b0\u51fa\u6765\u7684 API\uff0c\u53ef\u80fd\u67d0\u4e9b\u6d4f\u89c8\u5668\uff0c\u4f8b\u5982360\u6781\u901f\u7248\u4e4b\u7c7b\u7684\u5e76\u4e0d\u652f\u6301\uff08\u867d\u7136\u4f7f\u7528\u7684\u662f Chromium \u5185\u6838\uff0c\u4f46\u7248\u672c\u592a\u8001\uff09\uff0c\u4ee5\u53ca\u90e8\u5206\u8001\u65e7\u7684 Android \u8bbe\u5907\u3002<\/p>\n<p>\u8fd9\u4e2a API \u6211\u53ef\u662f\u559c\u6b22\u7684\u5f88\uff0c\u53ef\u4ee5\u8f7b\u677e\u89e3\u51b3\u4ee5\u524d\u4e00\u4e9b\u6bd4\u8f83\u5934\u75bc\u7684\u5b57\u7b26\u4e32\u5904\u7406\u9700\u6c42\u3002<\/p>\n<p>\u6bd4\u65b9\u8bf4\u641c\u7d22\u5173\u952e\u5b57\u7684\u9ad8\u4eae\u5339\u914d\u3002<\/p>\n<p>\u5c31\u50cf\u4e0b\u56fe\u6240\u793a\u8fd9\u6837\uff0c\u641c\u7d22\u5b57\u6bcd x\uff0c\u7ed3\u679c\u672c\u4eba\u540d\u5b57\u6709\u4e24\u4e2a\u5b57\u7684\u62fc\u97f3\u4e0e\u4e4b\u76f8\u7b26\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/search-match.png\" width=\"239\" height=\"182\" alt=\"\u540d\u5b57\u9ad8\u4eae\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u54a6\uff1f\u4e0d\u5bf9\u4e0d\u5bf9\uff0c\u4e0d\u662f\u8fd9\u4e2a\uff0c\u5e94\u8be5\u662f\u53e0\u8bcd\u5339\u914d\uff0c\u4e5f\u5c31\u662f\u5047\u8bbe\u6211\u7684\u540d\u5b57\u53eb\u505a\uff1a\u5f20\u946b\u946b\uff0c\u5219\u641c\u7d22\u201c\u946b\u201d\u7684\u65f6\u5019\u5e94\u8be5\u4e24\u4e2a\u5b57\u90fd\u9ad8\u4eae\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u56fe\u6211P\u4e0b\uff0c\u7a0d\u7b49\u2026\u2026<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/search-match2.png\" width=\"239\" height=\"124\" alt=\"\u5b57\u7b26\u5339\u914d\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5982\u679c\u53ea\u662f\u5339\u914d\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u63a5\u4f7f\u7528 <code>replace<\/code> \u5c31\u53ef\u4ee5\u4e86\uff0c\u7b80\u5355\u5230\u7206\u70b8\u3002<\/p>\n<pre>name = name.replace('\u946b', '&lt;mark&gt;\u946b&lt;\/mark&gt;');<\/pre>\n<p>\u53ef\u8981\u662f\u5e0c\u671b\u6240\u6709\u7684\u201c\u946b\u201d\u5b57\u90fd\u9ad8\u4eae\uff0c<code>replace<\/code> \u5c31\u4ece\u8001\u516d\u53d8\u6210\u4e8c\u4e94\u4ed4\u4e86\uff0c\u53ea\u80fd\u4f7f\u7528\u6b63\u5219\u8fdb\u884c\u66ff\u6362\u4e86\uff0c\u7531\u4e8e\u7528\u6237\u8f93\u5165\u6846\u8f93\u5165\u7684\u5185\u5bb9\u662f\u52a8\u6001\u7684\uff0c\u6240\u4ee5\uff0c\u53ea\u80fd\u4f7f\u7528 <code>new RegExp()<\/code> \u5b9e\u73b0\u3002<\/p>\n<pre>\/\/ \u5b9e\u9645\u5f00\u53d1\uff0cnew RegExp() \u4e2d  \r\nname = name.replace(new RegExp('\u946b', 'g'), '&lt;mark&gt;\u946b&lt;\/mark&gt;');<\/pre>\n<p>\u7136\u800c\u4f7f\u7528RegExp\u4f7f\u7528\u6709\u4e24\u5927\u7f3a\u70b9\uff1a<\/p>\n<p>1. \u96be\uff0c\u65b0\u4eba\u8868\u793a\u81e3\u59be\u8bb0\u4e0d\u4f4f\u554a\uff0c\u6bcf\u6b21\u4f7f\u7528\u90fd\u8981\u770b\u770b\u8bed\u6cd5\u662f\u4ec0\u4e48\uff0c\u54ea\u50cf<code>replace<\/code>\u65b9\u6cd5\u8fd9\u4e48\u901a\u4fd7\u6613\u61c2\u3002<br \/>\n2. \u70e6\uff0c\u52a8\u6001\u8f93\u5165\u5185\u5bb9\u4e0d\u53ef\u63a7\uff0c\u8981\u662f\u6709\u7279\u6b8a\u5b57\u7b26\uff0c\u8fd8\u9700\u8981\u8f6c\u4e49\uff0c\u4e0d\u7136\u4f5c\u4e3a RegExp \u7684\u53c2\u6570\u4f1a\u6709\u95ee\u9898\u3002<\/p>\n<p>\u597d\u5728\u73b0\u5728\u6709\u4e86 replaceAll \u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u8f7b\u677e\u66ff\u6362\u6240\u6709\u5339\u914d\u7684\u5b57\u7b26\u4e32\u4e86\uff0c\u7b80\u5355\u5230\u7206\u70b8+1\u3002<\/p>\n<pre>name = name.replaceAll('\u946b', '&lt;mark&gt;\u946b&lt;\/mark&gt;');<\/pre>\n<h3>\u4e8c\u3001replaceAll\u7684\u8bed\u6cd5\u548c\u7ec6\u8282<\/h3>\n<h4>\u8bed\u6cd5<\/h4>\n<p><code>replaceAll<\/code> \u8bed\u6cd5\u548c <code>replace<\/code> \u4e00\u6837\uff0c\u5747\u652f\u6301\u5b57\u7b26\u4e32\u66ff\u6362\u6216\u8005\u6b63\u5219\u66ff\u6362\uff1a<\/p>\n<pre>replaceAll(pattern, replacement)<\/pre>\n<p>\u4f46\u662f\u5177\u4f53\u7ec6\u8282\u4e0a\u4f1a\u6709\u4e00\u4e9b\u533a\u522b\u3002<\/p>\n<h4>\u7ec6\u8282<\/h4>\n<p>\u9996\u5148\uff0c<code>replaceAll<\/code> \u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4e00\u5b9a\u8981\u6709&#8217;g&#8217;\u8fd9\u4e2a\u5168\u5c40\u6807\u8bc6\u7b26\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\u7684 JS \u6267\u884c\u5c31\u4f1a\u62a5\u9519\uff1a<\/p>\n<pre>'hello world'.replaceAll(\/\\s\/, '');\r\n\/\/ \u4f1a\u62a5\u9519<\/pre>\n<blockquote><p>Uncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument<\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/2022-08-21_134130.png\" width=\"505\" height=\"207\" alt=\"\u62a5\u9519\u63d0\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5176\u6b21\uff0c\u548creplace\u65b9\u6cd5\u4e00\u6837\uff0creplaceAll\u4e5f\u662f\u8fde\u7a7a\u5b57\u7b26\u4e32\u4e5f\u80fd\u5339\u914d\u66ff\u6362\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>'\u5f20\u946b\u65ed'.replaceAll('', '_')<\/pre>\n<p>\u8fd4\u56de\u7684\u7ed3\u679c\u662f\uff1a&#8217;_\u5f20_\u946b_\u65ed_&#8217;<\/p>\n<p>\u5982\u4e0b\u622a\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/2022-08-21_134710.png\" width=\"250\" height=\"85\" alt=\"\u7a7a\u5b57\u7b26\u4e32\u66ff\u6362\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u5b9e\u73b0\u641c\u7d22\u9ad8\u4eae\u5339\u914d\u7684\u65f6\u5019\uff0c\u5982\u679c\u662f\u7a7a\u5b57\u7b26\u4e32\uff0c\u9700\u8981\u4e0d\u6267\u884c\u5339\u914d\u64cd\u4f5c\uff0c\u5426\u5219\u4f1a\u63d2\u5165\u5f88\u591a\u9884\u671f\u4e4b\u5916\u7684 <code>&lt;mark&gt;<\/code> \u5143\u7d20\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>IE\u6d4f\u89c8\u5668\u5e76\u4e0d\u652f\u6301\uff0c\u5176\u4ed6\u6d4f\u89c8\u5668\u5747\u5df2\u652f\u6301\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/2022-08-21_142214.png\" width=\"655\" height=\"262\" alt=\"replaceAll\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e09\u3001\u518d\u8bf4\u4e0b matchAll<\/h3>\n<p><code>matchAll<\/code> \u65b9\u6cd5\u4e5f\u662f\u6700\u8fd1\u4e09\u5e74\u624d\u652f\u6301\u7684\uff0c\u652f\u6301\u65f6\u95f4\u6bd4 <code>replaceAll<\/code> \u65b9\u6cd5\u8981\u65e9\u4e2a\u4e00\u5e74\u534a\u8f7d\u3002<\/p>\n<p>\u548c <code>match<\/code> \u65b9\u6cd5\u76f8\u6bd4\uff0c<code>matchAll<\/code> \u7684\u8fd4\u56de\u503c\u4e0d\u4ec5\u5305\u62ec\u5339\u914d\u7684\u5185\u5bb9\uff0c\u8fd8\u5305\u62ec\u5339\u914d\u7684\u5206\u7ec4\uff08\u4e5f\u5c31\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u90e8\u5206\uff09\u3002<\/p>\n<p>\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u5c55\u793a\u4e0b\u4e24\u8005\u7684\u533a\u522b\u3002<\/p>\n<pre>let str = 'author\\'s name is zxx';\r\nconst reg = \/\\s+([a-z]+)\/g;\r\n\r\nconsole.log(str.match(reg));\r\nconsole.log(str.matchAll(reg));<\/pre>\n<p>\u4e24\u8005\u7684\u8fd4\u56de\u503c\u5206\u522b\u662f\uff1a<\/p>\n<pre>match \u65b9\u6cd5\u8fd4\u56de\uff1a[' name', ' is', ' zxx']\r\nmatchAll \u8fd4\u56de\uff1aRegExpStringIterator\uff0c\u8f6c\u4e3a\u6570\u7ec4\u540e\u503c\u4e3a\uff1a\r\n\r\n[Array(2), Array(2), Array(2)]\r\n0: (2) [' name', 'name', index: 8, input: \"author's name is zxx\", groups: undefined]\r\n1: (2) [' is', 'is', index: 13, input: \"author's name is zxx\", groups: undefined]\r\n2: (2) [' zxx', 'zxx', index: 16, input: \"author's name is zxx\", groups: undefined]\r\nlength: 3<\/pre>\n<p>Chrome console\u9762\u677f\u4e2d\u6267\u884c\u540e\u7684\u7ed3\u679c\u793a\u610f\u4e3a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/2022-08-21_145409.png\" width=\"489\" height=\"310\" alt=\"matchAll \u622a\u56fe\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c<code>match<\/code> \u65b9\u6cd5\u5ffd\u7565\u7684\u5206\u7ec4\uff0c\u76f4\u63a5\u8fd4\u56de\u5339\u914d\u7684\u6570\u7ec4\u5185\u5bb9\uff0c\u800c <code>matchAll<\/code> \u8fd4\u56de\u7684\u8fed\u4ee3\u5668\u4e2d\u7684\u6570\u7ec4\u9879\u4e2d\u5c31\u5305\u542b\u4e86\u5206\u7ec4\u6355\u83b7\u7684\u5185\u5bb9\uff0c\u4ece\u4f5c\u7528\u4e0a\u6765\u770b\uff0c\u6709\u4e9b\u7c7b\u4f3c\u4e8e <code>regexp.exec()<\/code> \u65b9\u6cd5\uff08\u6570\u7ec4\u9879\u7684\u8fd4\u56de\u503c\u4e5f\u662f\u4e00\u6837\u7684\uff09\u3002<\/p>\n<p>\u4e0d\u8fc7\u7ec6\u8282\u4e0a\u8fd8\u662f\u6709\u533a\u522b\uff0c<code>matchAll<\/code> \u7684\u6b63\u5219\u662f\u4e00\u9524\u5b50\u4e70\u5356\uff0creg.lastIndex \u662f\u56fa\u5b9a\u4e0d\u53d8\u7684\uff0c\u6ca1\u6cd5\u50cf <code>regexp.exec()<\/code> \u4e00\u6837\u901a\u8fc7\u4fee\u6539 <code>lastIndex<\/code> \u4f7f\u6b63\u5219\u8868\u8fbe\u5f0f\u524d\u8fdb\u6216\u540e\u9000\u3002<\/p>\n<h4>\u8bed\u6cd5\u548c\u7ec6\u8282<\/h4>\n<p>\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>matchAll(regexp)<\/pre>\n<p>\u5176\u4e2d\uff0c<code>regexp<\/code> \u8868\u793a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5176\u4e2d\uff0c\u5fc5\u987b\u5e26\u6709 &#8216;g&#8217; \u5168\u5c40\u6807\u8bc6\u7b26\uff0c\u5426\u5219\u4f1a\u62a5\u9519\uff0c\u8fd9\u4e00\u70b9\u548c <code>replaceAll<\/code> \u65b9\u6cd5\u4e00\u81f4\u3002<\/p>\n<p>\u5f53\u6ca1\u6709\u4efb\u4f55\u5339\u914d\u7684\u65f6\u5019\uff0c<code>match<\/code> \u65b9\u6cd5\u8fd4\u56de\u7684\u662f <code>null<\/code>\uff0c<code>matchAll<\/code> \u5219\u8fd4\u56de\u7684\u662f\u53ef\u8fed\u4ee3\u8fed\u4ee3\u5668\uff0c\u8f6c\u6570\u7ec4\u540e\u662f\u7a7a\u6570\u7ec4\uff0c\u548c\u5339\u914d\u65f6\u5019\u7684\u6570\u636e\u7c7b\u578b\u4e00\u81f4\uff0c\u56e0\u6b64\uff0c\u5728\u5b9e\u64cd\u4e0a\uff0cJS \u6267\u884c\u51fa\u9519\u6982\u7387\u8981\u66f4\u5c0f\uff08\u5bf9\u4e8e\u65b0\u4eba\u800c\u8a00\uff09\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u76f4\u63a5\u770b\u56fe\uff0c\u7eff\u610f\u76ce\u7136\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/2022-08-21_150956.png\" width=\"658\" height=\"246\" alt=\"matchAll \u7eff\u610f\u76ce\u7136\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u56db\u3001\u7ed3\u8bed\u554a\u54c8<\/h3>\n<p>\u7531\u4e8e <code>matchAll<\/code> \u53ea\u80fd\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u6253\u4ea4\u9053\uff0c\u56e0\u6b64\uff0c<code>matchAll<\/code> \u5728 JS \u4ee3\u7801\u4e2d\u7684\u4f20\u64ad\u548c\u4f7f\u7528\u7387\u4e00\u5b9a\u662f\u5c0f\u4e8e <code>replaceAll<\/code> \u7684\uff0c\u56e0\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u5f88\u591a\u5f00\u53d1\u4eba\u5458\u7684\u8f6f\u808b\uff0c\u4e00\u77e5\u534a\u89e3\uff0c\u80fd\u907f\u5219\u907f\u3002<\/p>\n<p>\u8fd9\u663e\u7136\u4e0d\u662f\u957f\u4e45\u4e4b\u8ba1\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e00\u5b9a\u8981\u8ba4\u771f\u5b66\u4e60\uff0c\u53cd\u590d\u5b9e\u8df5\uff0c\u8981\u8fbe\u5230\u5b8c\u5168\u53ef\u4ee5\u81ea\u5df1\u624b\u5199\u590d\u6742\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5883\u754c\u624d\u53ef\u4ee5\u3002<\/p>\n<p>\u6709\u53e5\u8bdd\u662f\u600e\u4e48\u8bf4\u6765\u7740\uff0c\u51e1\u4e8b\u9700\u8981\u5bf9\u5b57\u7b26\u4e32\u5904\u7406\u7684\u5730\u65b9\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u884c\uff0c\u90a3\u5c31\u518d\u5199\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u5c31\u8bf4\u8fd9\u4e48\u591a\u5427\u3002<\/p>\n<p>\u6700\u8fd1\u6709\u4e2a\u7d27\u6025\u9879\u76ee\uff0c\u52a0\u73ed\u591a\uff0c\u540c\u65f6\u5728\u8d76\u300aCSS\u9009\u62e9\u5668\u4e16\u754c\u300b\u7684\u7a3f\u5b50\uff0c\u4ee5\u53ca\u5468\u672b\u9493\u9c7c\u6bd4\u8f83\u591a\uff0c\u6240\u4ee5\u6587\u7ae0\u66f4\u65b0\u6ede\u540e\u4e86\uff0c\u8fd9\u4e00\u5468\u4f1a\u8865\u4e0a\u3002<\/p>\n<p>\u5662\u5566\uff0c\u554a\u54c8\uff0c\u8bb0\u5f97\u70b9\u8d5e<button onclick=\"shareWeixin.click()\" class=\"entry-share-btn\">\u5206\u4eab<\/button>\u54e6\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10499\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10499<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202208\/jsall-cover.png\" width=\"160\" height=\"103\" alt=\"\u5c01\u9762\u56fe-\u7eb8\u98de\u673a\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u4ecb\u7ecd\u4e24\u4e2a\u6bd4\u8f83\u65b0\u7684\u90fd\u5e26\u6709 all \u5b57\u6837\u7684 JS API\uff0creplaceAll \u548c matchAll\uff0c\u589e\u5f3a\u4e86\u4f20\u7edf\u7684 replace \u548c match \u65b9\u6cd5\u7684\u80fd\u529b\uff0c\u770b\u770b\u81ea\u5df1\u9879\u76ee\u4e2d\u662f\u4e0d\u662f\u53ef\u4ee5\u7528\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[1849,1848,1846,1828,61,1847,371,222],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10499"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10499"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10499\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}