简体   繁体   English

txt文件删除网址到最后一个“ /”以获取文件

[英]txt file delete url to last “/” to get files

I have txt file contaning one url per row each url as: 我有txt文件,每个网址每行包含一个网址,如下所示:

://url/files.php?file=parent/children/file.pdf
://url/files.php?file=parent/children2/childrenofchildren2/file2.txt
......etc

I need help to cut everythink before last / in a row. 我需要帮助,以减少一切/最后/连续。 That is what I used in notepad++ regex mode (it doesnt work): 那就是我在notepad ++正则表达式模式下使用的(它不起作用):

^.+[/](.*)$

To get: 要得到:

file.pdf
file2.txt

But I am open to all waysof solving. 但是我对所有解决方案持开放态度。

Replace your line from left including / by nothing: 从左开始用/代替您的行:

sed 's/.*\///' file

or 要么

sed 's|.*/||' file

Output: 输出:

file.pdf
file2.txt

This solution may be more complicated than it needs to be, but it works! 该解决方案可能比需要的复杂,但它可以起作用!

A purely regex-based approach could be as follows: (([^\\/])*)((\\n)|($))/g 纯粹基于正则表达式的方法如下: (([^\\/])*)((\\n)|($))/g

Basically, it matches any number of non-newline and non \\ characters (([^\\/])*) and then stops when it either encounters a new line \\n or the end of the sequence $ . 基本上,它匹配任意数量的非换行符和非\\字符(([^\\/])*) ,然后在遇到换行符\\n或序列$的结尾时停止。 The global /g is also set, to allow it to match more than one instance! 还设置了全局/g ,以使其可以匹配多个实例!

I hope this helped! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM