Hi all,
I have a bunch of files, named like this:
My life - Jim Johnson.txt
Some long title with many words - Jack Simon Gudmundson.doc
Yes - James.xls
My question: what regex do I need to put (in FC 2014 build 650) the part behind the " - " in front, and the stuff which originally was before the " - " behind it? So, the result should be:
Jim Johnson - My life.txt
Jack Simon Gudmundson - Some long title with many words.doc
James - Yes.xls
Anyone who can shed some light on this? I'm all but mute in regex, I'm afraid, so bear with me.
Thanks!
Switch strings in filenames with regex?
Re: Switch strings in filenames with regex?
Hi there,
I think following lines should do the trick, however I'm no regex-pert, so keep that in mind and test it out properly before proceeding.
Search for:
Replace with:
Hope it helps.
Regards,
Kotty
I think following lines should do the trick, however I'm no regex-pert, so keep that in mind and test it out properly before proceeding.
Search for:
Code: Select all
([\w+\s|\w+]{1,})\s\-\s([\w+\s|\w+]{1,})
Code: Select all
$2\ \-\ $1
Regards,
Kotty
-
- Posts: 23
- Joined: 27.04.2015, 15:08
Re: Switch strings in filenames with regex?
Hi Kothy,Kotty wrote:Hi there,
I think following lines should do the trick, however I'm no regex-pert, so keep that in mind and test it out properly before proceeding.
Search for:Replace with:Code: Select all
([\w+\s|\w+]{1,})\s\-\s([\w+\s|\w+]{1,})
Hope it helps.Code: Select all
$2\ \-\ $1
Regards,
Kotty
Thanks for your code, which appears to do the trick in the cases I submitted. So, that's magnificent!!
But (alas, but...) there are also filenames with other characters, either in the first or in the second part, or even in both. Let's for instance take a comma.
Then the results get a bit weird - though undoubtedly not to skilled regex specialists.
Starting from this:
No comma - No problem.txt
A comma, in the first part - And a comma, in the second.txt
There is a comma, in the first part - No comma in the second.txt
There is no comma in the first part - A comma, in the second part.txt
I get this (with your code) :
No problem - No comma.txt
A comma,And a comma - in the first part, in the second.txt
There is a comma,No comma in the second - in the first part.txt
A comma - There is no comma in the first part, in the second part.txt
So, the comma (or other "special" characters) causes a hiccup. The "looked for" part appears to stop whenever there is a comma. The trick would be to make it Only stop at " - ".
But I do think your code is very close to the solution... Sadly, I'm in absolutely no position to get any closer to it myself. If you call yourself "no regex-pert", then I'm a complete and utter regex-neandertal
I hope you find the time to take a second look? Thanks!!
Re: Switch strings in filenames with regex?
Hi,
I think following regex should do the trick.
Search for:
'Replace with' regex stays the same.
Regards,
Kotty
I think following regex should do the trick.
Search for:
Code: Select all
([^.-]+)\s\-\s([^.-]+)
Regards,
Kotty
-
- Posts: 23
- Joined: 27.04.2015, 15:08
Re: Switch strings in filenames with regex?
Hi Kotty,Kotty wrote:Hi,
I think following regex should do the trick.
Search for:'Replace with' regex stays the same.Code: Select all
([^.-]+)\s\-\s([^.-]+)
Regards,
Kotty
Respectfully thanks!!! That indeed did the trick!
These filenames:
1 - 2.txt
1, a - 2.txt
1 - 2, b.txt
1, a - 2, b.txt
were neatly turned (thanks to your code) into:
2 - 1.txt
2 - 1, a.txt
2, b - 1.txt
2, b - 1, a.txt
Exactly what I was looking for! Thanks ever so much!!
Re: Switch strings in filenames with regex?
Glad to help.
Kotty
Kotty
Who is online
Users browsing this forum: No registered users and 29 guests