登录
首页 >  Golang >  Go问答

Golang - 如何从双引号开始抓取到末尾 - 需要抓取UUID

来源:stackoverflow

时间:2024-04-01 15:45:32 355浏览 收藏

推广推荐
免费电影APP ➜
支持 PC / 移动端,安全直达

目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《Golang - 如何从双引号开始抓取到末尾 - 需要抓取UUID》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~

问题内容

所以我有一个类似这样的字符串,它是嵌入了动态令牌的 html 内容。现在我需要在map[string]string中捕获一些令牌信息,这是令牌名称到uuid的关键。 我可以使用 strings.contains 方法检查该字符串,看看该块中是否存在我关心的标记(示例 emailappointmentcancellation)。现在,如果它包含此令牌,我需要获取与其关联的 uuid,直到引号末尾为止。我该怎么办呢。我需要一些正则表达式吗

<div style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);"><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);">Hello This is a friendly reminder about your upcoming appointment with </p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);"><br></p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);">Your appointment is: <span style="color: rgb(0, 0, 0);">{{Token "Stamps:appointmentDate" .}}</span>, <span style="color: rgb(0, 0, 0);">{{Token "Stamps:appointmentTime" .}}</span></p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);"><br></p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);">We appreciate your time and look forward to seeing you then!</p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);"><br></p><p style="font-family: Arial; font-size: 16px; line-height: 1.4; margin: 0px; color: rgb(0, 0, 0);">Sincerely, <span style="color: rgb(0, 0, 0);">{{Token "Forms:emailAppointmentCancellation:0386DA88-B658-43E8-863C-296A22D732FF" .}}</span><br><br><br></div>

正确答案


正则表达式

是的,我认为正则表达式将是一个简单的解决方案。我喜欢使用 https://regex101.com/ 来尝试一下。

一个简单的例子:https://regex101.com/r/ioRC6e/1

您可以使用标准库中的正则表达式包来编译它。

字符串操作

如果您可以非常确定数据格式,您也可以只浏览字符串并找到您的密钥:

https://goplay.tools/snippet/eRu-sKJr-se

以上就是《Golang - 如何从双引号开始抓取到末尾 - 需要抓取UUID》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>