我正在尝试创建一个提取 URL 的表达式
我想从网页中提取 URL,这些 URL 本身只是 URL,而不是超链接等,它们只是文本。一些示例是 http://www.example.com
、http://example.com
、www.example.com
等。我对正则表达式非常陌生,所以我在网上复制并粘贴了 20 个表达式,但都失败了。我不知道我这样做是否正确。任何帮助将不胜感激。
I want to extract URLs from a webpage these are just URLs by themselves not hyperlinks etc., they are just text. Some examples would be http://www.example.com
, http://example.com
, www.example.com
etc. I am extremely new at regex so I have copy and pasted like 20 expressions online all failed to work. I don't know if I am doing it right or not. Any help would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我写了一篇关于使用 Regex 来定位 HTML 页面中的链接的文章(目的是使用 JavaScript 在弹出窗口中打开外部链接或指向 PDF 等文档的链接)。
最终的正则表达式是:
^(?:[./]+)?(?:Assets|https?://(?!(?:www.)?integralist))
完整帖子在这里:
http://www .integralist.co.uk/javascript/regular-expression-to-open-external-links-in-popup-window/
该解决方案并不完美,但可能会帮助您指明正确的方向。
标记
I wrote a post on using Regex to locate links within a HTML page (the intent was to use JavaScript to open external links or links to documents such as PDF's etc in a popup window).
The final regex was:
^(?:[./]+)?(?:Assets|https?://(?!(?:www.)?integralist))
The full post is here:
http://www.integralist.co.uk/javascript/regular-expression-to-open-external-links-in-popup-window/
The solution wont be perfect but might help point you in the right direction.
Mark
您可能没有转义您的
.
。每一个都需要使用\.
。请访问 strfriend.com。它有一个 URL 示例,并以图形方式表示。
它建议的示例是:
You're probably not escaping your
.
s. You need to use\.
for each one.Take a look at strfriend.com. It has a URL example, and represents it graphically.
The example it suggests is: