使用 ruby 从文本中删除 url
给定一个文本,我想删除 url 部分并保留其他文本。
示例:
'bla bla bla... bla bla bla... http://bit.ly/someuri bla bla bla...'
成为
'bla bla bla... bla bla bla... bla bla bla...'
是否有任何 ruby 内置方法可以有效地做到这一点?
Given a text, I want to remove the url part and leave other text.
Example:
'bla bla bla... bla bla bla... http://bit.ly/someuri bla bla bla...'
to become
'bla bla bla... bla bla bla... bla bla bla...'
Is there any ruby build in method to do this efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用正则表达式:
Try with regex:
我刚刚发现 正则表达式 - 替换除 URL/URI 内的单词 并将代码修改为如下所示:
我在rails控制台中测试它并且它按预期工作:
如果有人有更好/有效的解决方案,我将投票或接受它。谢谢。
I just found Regular Expression - replace word except within a URL/URI and modify the code to be like this:
I test it in rails console and it worked as expected:
If anyone have better / effective solution, I will vote up or accept it. Thanks.