在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中通過正則表達式在字元串中查找字元串