Ruby 正则表达式匹配一个 url [英] Ruby Regular expression to match a url
问题描述
可能的重复:
正则表达式匹配 URL
正则表达式删除网址中的网页部分红宝石
我正在寻找用于解析文件中所有 url 的正则表达式.
我尝试了谷歌搜索后得到的许多正则表达式,但在一种或另一种情况下都失败了.我的想法是编写一个在开始时检查 http 或 https 是否存在的方法,它将匹配所有内容,直到看到一个空格.
有什么想法吗?
注意:我不需要解析 url,而是从文件中删除所有 url 或至少使其不可读.
I am in search of a regular expression for parsing all the urls in a file.
i tried many of the regular expression i got after googling but it fails in one or the other case . my idea is to write one which checks the presense of http or https at the begening and it will match everything untill it sees a blank space .
any ideas ?
NOTE : i dont need to parse the url but erase all the urls from a file or atleast make it unreadable .
推荐答案
你可以试试这个:
/https?:\/\/[\S]+/
\S
表示任何非空白字符.
The \S
means any non-whitespace character.
这篇关于Ruby 正则表达式匹配一个 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!