{"id":25890,"date":"2024-11-24T12:17:07","date_gmt":"2024-11-24T04:17:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25890\/"},"modified":"2024-11-24T12:17:07","modified_gmt":"2024-11-24T04:17:07","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e9%ab%98%e4%ba%ae%e6%97%a5%e5%bf%97%e5%86%85%e5%ae%b9%e4%b8%ad%e7%9a%84%e5%ad%97%e6%ae%b5%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25890\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173072196339553.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5<\/strong><\/p>\n<p>\u60a8\u6709\u4e00\u4e2a\u9700\u6c42\uff0c\u9700\u8981\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u65e5\u5fd7\u5185\u5bb9\u5e76\u9ad8\u4eae\u5339\u914d\u5230\u7684\u5b57\u6bb5\uff0c\u7c7b\u4f3c\u4e8e\u534e\u4e3a\u4e91\u7684\u5b9e\u73b0\u6548\u679c\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u6b64\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8f85\u4ee5 HTML \u548c CSS\u3002<\/p>\n<p><strong>Huawei Cloud \u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>Huawei Cloud \u4f7f\u7528 HTML \u548c CSS \u4e3a\u7279\u5b9a\u5b57\u6bb5\u6dfb\u52a0\u4e86\u4e00\u4e2a\u989d\u5916\u7684 span \u6807\u7b7e\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u4eae\u6548\u679c\u3002<\/p>\n<p><strong>\u624b\u52a8\u5b9e\u73b0<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u624b\u52a8\u5b9e\u73b0\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>const logContent = \"2022-03-10 10:30:15 [INFO] User john logged in\";\nconst regex = \/User (w+) logged in\/;\n\nconst match = logContent.match(regex);\n\nif (match) {\n  const highlighted = logContent.replace(regex, `&lt;span class=\"highlight\"&gt;$&amp;&lt;\/span&gt;`);\n  console.log(highlighted); \/\/ \u8f93\u51fa\uff1a2022-03-10 10:30:15 [INFO] &lt;span class=\"highlight\"&gt;User john logged in&lt;\/span&gt;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u4ee3\u7801\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7528\u6237\u540d\uff0c\u5e76\u7528 span \u6807\u7b7e\u5305\u88f9\u5339\u914d\u5230\u7684\u5b57\u6bb5\uff0c class \u8bbe\u7f6e\u4e3a &#8220;highlight&#8221;\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u9ad8\u4eae\u65e5\u5fd7\u5185\u5bb9\u4e2d\u7684\u5b57\u6bb5 \u60a8\u6709\u4e00\u4e2a\u9700\u6c42\uff0c\u9700\u8981\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u65e5\u5fd7\u5185\u5bb9\u5e76\u9ad8\u4eae\u5339\u914d\u5230\u7684\u5b57\u6bb5\uff0c\u7c7b\u4f3c\u4e8e\u534e\u4e3a\u4e91\u7684\u5b9e\u73b0\u6548\u679c\u3002 \u8981\u5b9e\u73b0\u6b64\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8f85\u4ee5 HTML \u548c CSS\u3002 Huawei Cloud \u89e3\u51b3\u65b9\u6848 Huawei Cloud \u4f7f\u7528 HTML \u548c CSS \u4e3a\u7279\u5b9a\u5b57\u6bb5\u6dfb\u52a0\u4e86\u4e00\u4e2a\u989d\u5916\u7684 span \u6807\u7b7e\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u4eae\u6548\u679c\u3002 \u624b\u52a8\u5b9e\u73b0 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u624b\u52a8\u5b9e\u73b0\u7684\u4ee3\u7801\u793a\u4f8b\uff1a const logContent = &#8220;2022-03-10 10:30:15 [INFO] User john logged in&#8221;; const regex = \/User (w+) logged in\/; const match = logContent.match(regex); if (match) { const highlighted = logContent.replace(regex, `&lt;span class=&#8221;highlight&#8221;&gt;$&amp;&lt;\/span&gt;`); console.log(highlighted); \/\/ \u8f93\u51fa\uff1a2022-03-10 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25890","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=25890"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25890\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}