{"id":208027,"date":"2025-07-08T13:45:34","date_gmt":"2025-07-08T05:45:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208027\/"},"modified":"2025-07-08T13:45:34","modified_gmt":"2025-07-08T05:45:34","slug":"%e5%9c%a8%e7%a9%ba%e6%a0%bc%e4%b8%8a%e5%88%86%e5%89%b2%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%88%e4%bd%86%e4%b8%8d%e6%98%af%e5%85%a8%e9%83%a8-%ef%bc%9f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208027\/","title":{"rendered":"\u5728\u7a7a\u683c\u4e0a\u5206\u5272\u5b57\u7b26\u4e32\uff08\u4f46\u4e0d\u662f\u5168\u90e8&#8230;&#8230;\uff1f\uff09"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5728\u7a7a\u683c\u4e0a\u5206\u5272\u5b57\u7b26\u4e32\uff08\u4f46\u4e0d\u662f\u5168\u90e8&#8230;&#8230;\uff1f\uff09<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 23:45:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728Golang\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5728\u7a7a\u683c\u4e0a\u5206\u5272\u5b57\u7b26\u4e32\uff08\u4f46\u4e0d\u662f\u5168\u90e8&#8230;&#8230;\uff1f\uff09\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u8fd9\u91cc\u6211\u6709\u4e00\u4e2a\u6a21\u62df\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u5355\u4e2a\u5b57\u7b26\u4e32\u4e2d\u591a\u4e2a\u5355\u8bcd\u7684\u5355\u4e2a\u53c2\u6570\uff0c\u4f8b\u5982<code>\u201chello1 hello2 hello3 hello4 hello5 hello6 hello7\u201d<\/code>\u7b49<\/p>\n<p>\u8be5\u51fd\u6570\u5c06\u9996\u5148\u8fdb\u884c\u5339\u914d\u4ee5\u67e5\u770b\u5355\u8bcd <code>content<\/code> \u662f\u5426\u5728\u5b83\u6536\u5230\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u7136\u540e\u7ee7\u7eed\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u53c2\u6570\u3002\u5982\u679c\u4e0e <code>content<\/code> \u4e0d\u5339\u914d\uff0c\u5219\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<p>\u6211\u7684 <code>dosomething<\/code> \u51fd\u6570\u6b63\u5728\u5904\u7406\u8fd9\u4e9b\u6570\u636e\uff0c\u9884\u8ba1\u6709 5 \u4e2a\u53c2\u6570\u3002<\/p>\n<p>\u6211\u73b0\u5728\u7684\u95ee\u9898\u662f\uff0c\u5982\u4f55\u7528\u5206\u9694\u7b26<em>\u7a7a\u683c<\/em>\u5206\u5272\u5b83\u4eec\uff0c\u4f46<code>hello5<\/code>\u4e4b\u540e\u7684\u6240\u6709\u5185\u5bb9\u90fd\u5e94\u8be5\u662f\u4e0b\u9762<code>arg5<\/code>\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u76ee\u524d\u6211\u65e0\u6cd5\u786e\u5207\u77e5\u9053 <code>mystring<\/code> \u5c06\u5305\u542b\u591a\u5c11\u53c2\u6570\uff0c\u56e0\u6b64\u8fde\u63a5\u56fa\u5b9a\u53c2\u6570\u4e0d\u8d77\u4f5c\u7528\uff0c\u5b83\u9700\u8981\u662f\u52a8\u6001\u7684\uff08\u8fd9\u662f\u6211\u7684\u5047\u8bbe\uff09\u3002<\/p>\n<p>\u6211\u5e0c\u671b\u8fd9\u662f\u6709\u9053\u7406\u7684<\/p>\n<pre>func testing(mystring) {\n    matched, err := regexp.MatchString(`content`, mystring)\n    if err != nil { panic() }\n    if matched {\n        r := regexp.MustCompile(\"[^\\\\s]+\")\n        arguments := r.FindAllString(clientRequest, -1)\n        arg1 := string(arguments[1])\n        arg2 := string(arguments[2])\n        arg3 := string(arguments[3])\n        arg4 := string(arguments[4])\n        arg5 := string(arguments[5])\n        dosomething(arg1, arg2, arg3, arg4, arg5)\n    } else {\n        log.Println(\"Not matched\")\n    }\n}\n<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p> \u6b63\u662f\u60a8\u60f3\u8981\u7684\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5c0f\u6f14\u793a\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    fmt.printf(\"%q\\n\", strings.splitn(\"a b c d e f g\", \" \", 5))\n}\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>[\"a\" \"b\" \"c\" \"d\" \"e f g\"]<\/pre>\n<p>\u6211\u8fd8\u5efa\u8bae\u6dfb\u52a0\u4e00\u4e2a\u989d\u5916\u7684 <code>if<\/code> \u8bed\u53e5\u6765\u68c0\u67e5 <code>strings.splitn<\/code> \u8fd4\u56de\u6b63\u786e\u957f\u5ea6\u7684\u5207\u7247\u3002<\/p>\n<p>\u5982\u679c\u60a8\u786e\u5b9a\u8981\u641c\u7d22\u7684\u662f\u5355\u8bcd\u800c\u4e0d\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\uff0c\u5219\u60a8\u53ef\u4ee5\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\uff1a<\/p>\n<pre>exists := strings.Index(str, \"content\")<\/pre>\n<p>\u8fd9\u5c06\u8fd4\u56de <code>content<\/code> \u51fa\u73b0\u7684\u7b2c\u4e00\u4e2a\u7d22\u5f15\uff0c\u5982\u679c\u672a\u627e\u5230\uff0c\u5219\u8fd4\u56de <code>-1<\/code>\u3002\u5982\u679c\u627e\u5230\u5339\u914d\u9879\uff0c\u5219\u53ef\u4ee5\u62c6\u5206\u5b57\u7b26\u4e32\uff0c\u76f4\u5230\u627e\u5230 <code>index-1<\/code>\u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2a\u6f14\u793a\u793a\u4f8b\u53ef\u4ee5\u5e2e\u52a9\u60a8\uff1a <\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5728\u7a7a\u683c\u4e0a\u5206\u5272\u5b57\u7b26\u4e32\uff08\u4f46\u4e0d\u662f\u5168\u90e8&#8230;&#8230;\uff1f\uff09\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208027","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208027"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208027\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}