使用正则表达式清理 URL [英] Clean Urls with regular expression
问题描述
我有一千行数据,如
http://xxxx.com/xxx-xxx-xxx-xxxx/ 60% 2 每周 2014-01-01 00:00
http://xxxx.com/xxx-xxx-xxx-xxxx/ 60% 2 Weekly 2014-01-01 00:00
想要删除每个网址中/之后的所有内容
want to remove everything after / in every url
(输出应该在如下所示的干净网址中)
(output should be in clean url like below)
http://xxxx.com/xxx-xxx-xxx-xxxx/
谢谢
推荐答案
按 Ctrl+H 使用替换菜单,并确保启用正则表达式.那么,
Use the replace menu by pressing Ctrl+H, and make sure regular expressions are enabled. Then,
查找 (^.*\/).*
和替换 $1
:https://regex101.com/r/lJ4lF9/12
或者,查找 (?m)(^.*\/).*
和 Replace $1
:https://regex101.com/r/lJ4lF9/13
说明:
在捕获组中,查找字符串 (^
) 后跟任意次数 (.*
) 直到最后一个/",然后任意次数.将替换为捕获的组,将其引用为 $1
.
Within a capture group, Find the start of the string (^
) followed by anything any number of times (.*
) until the last "/", then anything any number of times. Replace with the captured group by referencing it as $1
.
(?m)
这篇关于使用正则表达式清理 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!