为了账号安全,请及时绑定邮箱和手机立即绑定

Golang - 使用正则表达式提取链接

Golang - 使用正则表达式提取链接

Go
慕尼黑8549860 2022-12-13 16:09:32
Golang - 使用正则表达式提取链接我需要example.de在 Go 中使用 Regex从特定域中的文本获取所有链接以下是应提取的所有可能链接:https://example.de  https://example.de/ https://example.de/home https://example.de/home/ https://example.de/home some text that should not be extracted https://abc.example.de https://abc.example.de/ https://abc.example.de/home https://abc.example.de/home https://abc.example.de/home some text that should not be extracted我已经尝试过的我使用这个网站来检查我的正则表达式是否正确: https ://regex101.com/r/ohxUcG/2 以下是失败的组合:https?://*.+example.de*.+表达失败,https://abc.example.de/a1b2c3    dsadsa将整个文本转移到\n而不是https://abc.example.de/a1b2c3没有dsadsahttps?://*.+example.de*.+\s(\w+)$这会获取仅以空格终止的链接,但有时链接可以以\n或\t等终止。
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

您可以使用

(?:https?://)?(?:[^/.]+\.)*\bexample\.de\b(?:/[^/\s]+)*/?

请参阅正则表达式演示详情

  • (?:https?://)?- 一个可选的http://https://字符串

  • (?:[^/.]+\.)* - 一个或多个字符的零个或多个序列,除了 a/.chars,然后是.char

  • \bexample\.de\b- 一个完整的词example.de

  • (?:/[^/\s]+)*- 零次或多次重复/,然后是除空格以外的一个或多个字符,以及/

  • /?- 一个可选的/字符。


查看完整回答
反对 回复 2022-12-13
  • 1 回答
  • 0 关注
  • 257 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号