RegEx Newbie

Discussion, questions and support.
Post Reply
Message
Author
JohnM243
Posts: 2
Joined: 24.03.2022, 15:08

RegEx Newbie

#1 Post by JohnM243 » 24.03.2022, 15:18

I'm a total RegEx newbie and need some help!

I have a directory with hundreds of file names in this format:

Prefix-CityName-St-Country-Date

The problem I have is that CityName can be 1, 2, or 3 words, separated by dashes. I need it to be changed to one word. There are about 70 multiple word city names.

Examples:

Prefix-City-Name-St-Country-Date needs to be changed to Prefix-CityName-St-Country-Date

Prefix-3Word-City-Name-St-Country-Date must be changed to Prefix-3WordCityName-St-Country-Date

I tried to do this but was unable to: I know nothing about RegEx!

Anyone able to help?

Thanks very much,

John

matandra
Posts: 6
Joined: 23.02.2014, 19:46

Re: RegEx Newbie

#2 Post by matandra » 15.04.2022, 15:36

This can be achieved with the following regular expression
search for: ([^-]+-[^-]+)(-([^-]+))?(-([^-]+))?(-[^-]+-[^-]+-[^-]+)
replace with: $1$3$5$6
Do not forget to activate the checkbox "Regular expression"

JohnM243
Posts: 2
Joined: 24.03.2022, 15:08

Re: RegEx Newbie

#3 Post by JohnM243 » 15.04.2022, 15:56

Thanks very much @matandra, I will try that out when I have a couple of minutes!

John

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests