用于匹配除数字和定义的单词之外的任何字符的正则表达式

RegEx for matching any char except numbers and defined words

我正在尝试使用支持 regex 的 Advanced Renamer 批量重命名我的文件。

我想匹配所有字符以排除这些字符并创建一个新文件名,但要保留剧集数和特定单词以区分 OVA 等常规剧集。

我尝试了 \D[^OVA] 和其他类似的方法但没有任何效果:

Hunter x Hunter 02 = 02

Hunter x Hunter OVA 08 = OVA 08

Hunter x Hunter OVA Greed Island Final 01 = OVA Island 01

我猜您希望排除 OVA 和所有号码。然后,this expression可能会帮助你这样做或设计一个:

([^OVA0-9]+)*

图表

此图显示了表达式的工作原理,您可以在此 link:

中可视化其他表达式


如果您希望添加要排除的单词列表,this expression 可以这样做:

([\S\s]*?)([0-9]+|OVA|Any|Thing|Else|That|You|Like)

您可以使用 | 添加您可能想要排除的任何其他词。

正则表达式描述图

JavaScript 测试

const regex = /([\S\s]*?)([0-9]+|OVA|Any|Thing|Else|That|Like)/gm;
const str = `Hunter x Hunter VOA Greed Island Final 01 = OVA Island 01`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}