Tristanisginger
Tristanisginger

Reputation: 2683

Regular expression to replace part of URL

I have over 5000 lines like so:

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

I need to replace:

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

With

www.example.com/de/enquiry

Unfortunately I am useless at regular expressions and don't know where to start. Using sublime text what is the correct regular expression to find all occurrences of /?/?-company-domaincheck

Upvotes: 0

Views: 1008

Answers (1)

jp-jee
jp-jee

Reputation: 1523

The regex

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

will match any of

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

(assuming that ? only contains [A-Za-z]), as in your examples.

To match another number of folders in between, replace {3} by the desired number (or by + for any).

Upvotes: 2

Related Questions