其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

guid的正则表达式

GG网络技术分享 2025-03-18 16:15 1


问题描述:

I\'m having some issues with following regular expressions.

Error: Invalid operation

re := regexp.MustCompile(\"(([a-f0-9]+\\-)+[a-f0-9]+)\\/(.*?)\\/(.*?);version=(\\d*)\")

match := re.FindStringSubmatch(hex.EncodeToString([]byte(href)))

fmt.Println(match)

my test strings that I\'m trying to match are

/data/1221a7f47-84c1-445e-a615-ff82d92e2eaa/article/jane;version=1493756861347

/data/1221a7f47-84c1-445e-a615-ff82d92e2eaa/article/john;version=1493756856398

Expecting following strings after match

  1. 1221a7f47-84c1-445e-a615-ff82d92e2eaa
  2. article
  3. jane
  4. 1493756856398

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

以下正则表达式存在一些问题。</ p>

错误:无效操作</ p>

</ blockquote>

  re:= regexp.MustCompile(“((([a-f0-9] + \\-)+ [  a-f0-9] +)\\ /(。*?)\\ /(。*?); version =(\\ d *)“)

match:= re.FindStringSubmatch(hex.EncodeToString([] byte(href) ))

fmt.Println(match)

</ code> </ pre>

我要匹配的测试字符串是</ p>

  /数据/ 1221a7f47-84c1-445e-A615-ff82d92e2eaa /条/简;版本= 1493756861347 

\\ N /数据/ 1221a7f47-84c1-445e-A615-ff82d92e2eaa /条/约翰;版本= 1493756856398

</代码 > </ pre>

匹配后期望以下字符串</ p>

  1. 1221a7f47-84c1-445e-a615-ff82d92e2eaa </ li>

  2. article </ li>

  3. jane </ li>

  4. 1493756856398 </ li>

    </ ol>

    </ div>

    网友观点:

    You need to fix the first line, declare the regex correctly. Try these:

    Using backslashes (to escape)

    re := regexp.MustCompile(\\\"(([a-f0-9]+\\\\-)+[a-f0-9]+)\\\\/(.*?)\\\\/(.*?);version=(\\\\d*)\\\")

    Try it out

    Using raw string literals (`)

    re := regexp.MustCompile(`(([a-f0-9]+\\-)+[a-f0-9]+)\\/(.*?)\\/(.*?);version=(\\d*)`)

    Try it out

    笔记:前端自学基础之正则表达式

    转义字符"\\"

    多行字符串:

    document.body.innerHTML = "\\

    <div></div>\\

    <span><\\span>\\

    ";

    字符串换行符\\n;行结束:\\r;制表符:\\t(缩进)

    正则表达式 RegExp

    正则表达式的作用:匹配特殊字符或有特殊搭配原则的字符的最佳选择。 贪婪匹配原则。

    两种创建方式:

    1、字面量 (推荐) /pattern/attributes

标签:

提交需求或反馈

Demand feedback