在Go中通过正则表达式在字符串中查找字符串
问题描述:
I\'m trying to write a regex that returns a string to me
I have a full string like this:
1 2 |
@badges=moderator/1,premium/1;color=#00FF80;display-name=gempir;emotes=;id=d0358df2-f0a1-4600-910e-515ec52b1baa;mod=1;room-id=99659894;sent-ts=1489250823035;subscriber=0;tmi-sent-ts=1489250823211;turbo=0;user-id=77829817;user-type=mod :gempir!gempir@gempir.tmi.twitch.tv PRIVMSG #gempbot :!status |
and what to find the command \"PRIVMSG\" because there are similar full strings that have different commands. Like this:
1 2 |
@ban-duration=20;ban-reason=Banned\\slink;room-id=11148817;target-user-id=78424343 :tmi.twitch.tv CLEARCHAT |
If you are interested these are twitch irc messages with ircv3 tags
now I have this regex:
1 2 |
^@(.*)\\s:(.*?)tmi.twitch.tv\\s |
how do I use the regex or a similar one in Go to find the string im looking for?
I wanted to avoid splitting again and again because it seems kinda unreasonable and hard to read. I think a regex can fix all my problems.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议
我正在尝试编写一个向我返回字符串的正则表达式</ p>
我有这样一个完整的字符串:</ p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
@ badges =主持人/ 1,高级/ 1; color =#00FF80; display-name = gempir; emotes =; id = d0358df2-f0a1-4600-910e-515ec52b1baa; MOD = 1;房间-ID = 99659894;发送-TS = 1489250823035;订户= 0; TMI-发送-TS = 1489250823211;涡轮= 0;用户ID = 77829817;用户 type = mod:gempir!gempir@gempir.tmi.twitch.tv PRIVMSG #gempbot:!status </ code> </ pre> <p>以及查找命令“ PRIVMSG”的内容,因为存在 具有不同命令的类似完整字符串。 像这样:</ p> <pre> <code> @ ban-duration = 20; ban-reason = Banned \\ slink; room-id = 11148817; target-user-id = 78424343:tmi.twitch。 电视CLEARCHAT </ code> </ pre> <p>如果您有兴趣,这些是带有ircv3标签的抽搐irc消息</ p> <p>现在我有此正则表达式:</ p> <pre> <代码> ^ @(。*)\\ S:(?*)tmi.twitch.tv \\ S </代码> </ PRE> <p> 我该如何在Go中使用正则表达式或类似的正则表达式来查找我正在寻找的字符串?</ p> <p>我想避免一次又一次地拆分,因为这似乎有点不合理且难以理解。 我认为正则表达式可以解决我所有的问题。</ p> </ div> <h3>网友观点:</h3> <div> <p>The following <em>regex</em> should do it ...</p> <pre><code>(?<=twitch.tv\\s)\\w+(?=\\s#) |
see regex demo
Just not to be anchored to the web-address (which can be changed some time) i\'d prefer this kind:
1 2 |
([A-Z]+)(\\s#.+)?$ |
GO字符串
字符串
在GO语言中,字符串是不可变的字节序列,只能通过重新赋值改变变量的值。
如下代码:
由于网站搬家,部分链接失效,如无法下载,请联系站长!谢谢支持!
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 在Go中通过正则表达式在字符串中查找字符串
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 在Go中通过正则表达式在字符串中查找字符串