REGEX语法\(。*\)假设删除()之间的()和所有字符。它实际上是如何工作的?
我是Regex世界的新手。我想重命名文件名末尾添加的时间戳的文件。基本上删除扩展程序之前的最后25个字符。
命名文件名的示例:
IMG523314(2021-12-05-14-51-25_UTC).jpg > IMG523314.jpg
Test run1(2021-08-05-11-32-18_UTC).txt > Test run1.txt
要在.extension之前删除25个字符(2021-12-05-14-51-25_UTC) 或者,如果您愿意,请卸下始终存在的括号()以及括号内的所有内容。 右支架总是一个点之后。 “
如上图中所示,REGEX语法会选择上述吗?如果是,我想知道它实际上是如何工作的吗?
非常感谢, 担
I am new to Regex world. I would like to rename the files that have time stamp added on the end of the file name. Basically remove last 25 characters before the extension.
Examples of file names to rename:
IMG523314(2021-12-05-14-51-25_UTC).jpg > IMG523314.jpg
Test run1(2021-08-05-11-32-18_UTC).txt > Test run1.txt
To remove 25 characters before the .extension (2021-12-05-14-51-25_UTC)
or if you like, remove the brackets ( ) which are always there and everything inside the brackets.
After the right bracket is always a dot '. "
Will Regex syntax as shown in the Tittle here, select the above? If yes, I wonder how it actually works?
Many Thanks,
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是
\(。*\)
将选择paranthesis以及其中的任何内容。假设当您询问它的工作方式时,您的意思是为什么符号工作它们的工作方式,这是一个崩溃:
\(
&\)
:Paranthesis是Regex中的特殊字符,它们表示群体,因此,为了正确匹配它们,您需要用后斜切逃脱它们。。
:周期是通配符匹配器,这意味着它们匹配任何单个字符。*
:星号是一个量词,这意味着将零匹配到上一个匹配器的无差速。因此,要将所有内容整合在一起:
,这是由于闭合支架的要求,您将星号的无限匹配限制为他们里面的角色。
Yes
\(.*\)
will select the paranthesis and anything inside of them.Assuming when you ask how it works you mean why do the symbols work how they do, heres a breakdown:
\(
&\)
: Paranthesis are special characters in regex, they signify groups, so in order to match them properly, you need to escape them with backslashes..
: Periods are wildcard matcher, meaning they match any single character.*
: Asterisks are a quantifier, meaning match zero to inifite number of the previous matcher.So to put everything together you have:
Because of that closing bracket requirement, you put a limit to the infinite matching of the asterisk and therefore only grab the parenthesis and characters inside of them.
是的,有可能:
和
Yes, it's possible:
and
Explanation:
\(*\)
, that is, anything inside paranthesis