Page 1 of 1

RegEx Newbie

Posted: 24.03.2022, 15:18
by JohnM243
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

Re: RegEx Newbie

Posted: 15.04.2022, 15:36
by matandra
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"

Re: RegEx Newbie

Posted: 15.04.2022, 15:56
by JohnM243
Thanks very much @matandra, I will try that out when I have a couple of minutes!

John