简体   繁体   English

搜索模式(正则表达式)python

[英]Search pattern (Regex) python

I downloaded this tool (http://www3.telus.net/pfrank/) to rename thousands of file names (that I inherited) that has bunch of illegal characters. 我下载了此工具(http://www3.telus.net/pfrank/),以重命名成千上万个包含一堆非法字符的文件名(我继承)。 I am trying to find ... in any where in the file name and replace it with nothing. 我正在尝试在文件名中的任何位置找到...,并将其替换为空。

I tried [...] but it only removes from the end of file name. 我尝试过,但是它只会从文件名的末尾删除。 Any suggestion ? 有什么建议吗?

As Kash said, use \\.{3} rather than [...] . 正如Kash所说,请使用\\.{3}而不是[...] The problem is that the period is a special character in regular expressions. 问题在于句点在正则表达式中是一个特殊字符。 It means "any character". 它的意思是“任何字符”。 So, in order to represent a literal period, you much escape it with the backslash. 因此,为了表示一个字面量,您可以使用反斜杠将其转义。 \\.{3} looks for any occurances of exactly three periods in a row. \\.{3}查找连续三个周期内的任何事件。 \\.+ looks for any occurrence of one or more periods in a row (careful, will look for single periods). \\.+查找连续出现的一个或多个句点(小心,将查找单个句点)。 \\.\\.+ will find all instances of two or more periods in a row, which I expect is what you're looking for. \\.\\.+将连续查找两个或多个句点的所有实例,我希望这是您要查找的。

Use \\.+ instead of [...] . 使用\\.+代替[...]
If you are looking for specifically 3 dots, then \\.{3} 如果要寻找3个点,则\\.{3}

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

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