使用正则表达式清理 URL [英] Clean Urls with regular expression

查看:42
本文介绍了使用正则表达式清理 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一千行数据,如

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆