我正在尝试重命名文件夹中的文件,该文件夹中的文件名称如下:
['A_LOT_OF_TEXT'].pdf&blobcol=urldata&blobtable=MungoBlobs
- 我基本上想获取“.pdf”之前的所有内容,包括“.pdf”
安装 brew rename 后,我尝试使用它但它不起作用:
rename -n -v '.*?(.pdf)' *
我得到错误:
Using expression: sub { use feature ':5.28'; .*?(.pdf) }
syntax error at (eval 2) line 1, near "; ."
有什么解决办法吗?
最佳答案
你当然想要
rename -n -v 's/^(.*?\.pdf).*/$1/' *
参见 regex proof .一旦您确定该表达式适合您,请删除 -n
。
解释
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to $1:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
pdf 'pdf'
--------------------------------------------------------------------------------
) end of $1
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
关于regex - 在 Mac 终端上使用 Regex 重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67655823/