regex - 如何使用前缀从文件名中删除前导数字?
问题描述
我有很多这样的文件
0678 - Puzzle Series Vol. 5 - Slither Link (J).nds
0679 - Puzzle Series Vol. 6 - Illust Logic (J).nds
0680 - Puzzle Series Vol. 7 - Crossword 2 (J).nds
并想删除前四位数字和破折号,所以它们变成
Puzzle Series Vol. 5 - Slither Link (J).nds
Puzzle Series Vol. 6 - Illust Logic (J).nds
Puzzle Series Vol. 7 - Crossword 2 (J).nds
当我尝试时,prename
我得到
$ prename -i 's/???? - (.+nds)/$1/' *nds
Quantifier follows nothing in regex; marked by <-- HERE in m/? <-- HERE ??? - (.+nds)/ at (eval 1) line 1.
问题
有人可以看到我做错了什么吗?
解决方案
?
并不意味着你认为它意味着什么。这意味着前一个原子是可选的。例如/^ab?\z/
匹配a
和ab
。
用于.
匹配除换行符以外的任何字符。/s
使.
任何字符,句号。
s/.... - (.+nds)/$1/
s/.{4} - (.+nds)/$1/ # Readability improvement.
s/.{4} - (.+nds)/$1/s # No need to prevent `.` from matching a LF.
s/^.{4} - (.+nds)/$1/s # Better to anchor for readability if nothing else.
s/^\d{4} - (.+nds)/$1/s # A bit more restrictive, and more self-documenting.
s/^\d+ - (.+nds)/$1/s # Do we really need to check that there are exactly 4?
s/^\d+ - (.*)/$1/s # No point in checking if `nds` is contained.
s/^\d+ - //
推荐阅读
- python - 在 (py)Spark 数据框中匹配多个正则表达式
- linux - 修改 bash 脚本,使其在检查实体类型后,还列出输入实体的详细信息
- powershell - 使用 Start-Process 卸载应用程序失败
- javascript - 小组件不显示
- amazon-web-services - 是否可以将子域重定向到不同的域(在 CloudFront 分配之后)?
- javascript - Blazor 自动完成标记
- html - 谷歌应用脚本 gotoconnect / jive 虚拟传真 - 没有从电子邮件中找到附件
- laravel - Laravel 路由获取后缀不起作用
- c# - 从 MS.Win32.TaskScheduler 输出到文件
- java - 导入 javax.xml.bind 无法解析