我有一个 txt 文件,每行一个 url,每个 url 为:
://url/files.php?file=parent/children/file.pdf
://url/files.php?file=parent/children2/childrenofchildren2/file2.txt
......etc
我需要帮助来削减连续最后一个 /
之前的所有想法。这就是我在 notepad++ 正则表达式模式中使用的(它不起作用):
^.+[/](.*)$
得到:
file.pdf
file2.txt
但我对所有解决方法持开放态度。
最佳答案
将包括 /
在内的左边的行替换为空:
sed 's/.*\///' file
或
sed 's|.*/||' file
输出:
file.pdf file2.txt
关于regex - txt文件删除url到最后 "/"得到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45578253/