正则表达式替换部分URL

时间:2014-10-30 17:15:38

标签: regex url

我有超过5000行像这样:

www.example.com/de/germany/germany-company-domaincheck
www.example.com/de/germany/germany-company-question
www.example.com/de/germany/index
www.example.com/de/germany-page
www.example.com/de/france/france-company-domaincheck
www.example.com/de/france/france-company-question
www.example.com/de/france/index
www.example.com/de/france/france-page

我需要替换:

www.example.com/de/germany/germany-company-domaincheck
www.example.com/de/france/france-company-domaincheck
etc

使用

www.example.com/de/enquiry

不幸的是,我在正则表达式上没用,也不知道从哪里开始。使用sublime文本什么是正确的正则表达式来查找所有出现的/?/? - company-domaincheck

1 个答案:

答案 0 :(得分:2)

正则表达式

/(www\.example\.com)(\/\w+){3}(-company-domaincheck)/g

将匹配任何

www.example.com/?/?/?-company-domaincheck

(假设?仅包含[A-Za-z]),如示例所示。

要匹配其中的其他数量的文件夹,请将{3}替换为所需的数字(或+替换任何文件夹。)