I have run a batch rename that has gone wrong and can't undo. Now my files contain repetitions: Asia.jpgAsia.jpgAsia.jpgAsia.jpg
Is there a way to use String Substitution to identify and remove repetitions?
You can use what are called "regular expressions" to deal with complex patterns. Google the term for tutorials and sample code.
Yes, this sort of pattern matching is perfect for a regular expression based string substitution.
One of many possible regular expressions would be:
If you had a mixture of file extensions (.jpg .tif .psd etc), then different code would be used rather than just the .jpg extension.
Some other valid regex find/replace combos include:
(\w+\.jpg|\w+\.psd)(.+) $1 (.+)([A-Z][a-z0-9]*?\.\w*?$) $2 (.+)([A-Z][a-z0-9]*?\.[^\.]+$) $2
You can use one of the many sites such as regex101.com to explore the expressions as there are other valid choices, some more elegant than others, some more robust, some may be equivalent etc.
Thank you for your reply, I'm trying to get my head around regex!
My example was actually wrong, what I have at the moment is:
that should become
Can you recommend a solution to this?
Having multiple examples would help as the pattern may not be consistent.
For example, if I presumed that the pattern:
Was always the first 4 characters from the left, or the last 4 characters from the right after the file extention... But that would not help for EuropeEuropeEuropeEurope.jpg
If your pattern is an uppercase letter followed by varying lengths of lowercase letters, then one of my previous suggestions works:
The previous regex presumed a pattern of the first character being an uppercase letter, followed by any combination of letters or numbers...
This may (or may not be) be more robust:
Again we need samples, samples, samples...
This is all very useful, thank you!
I don't have any patterns unfortunately, the only pattern is the repetition.
Sometimes the title starts with an uppercase, some others with lower case. Some contain spaces and some underscores. I feel this is very complicated.
I'll try and see if I can run multiple batch rename without making it any worse.
To try stop rename problems, I'd suggest that you play things safe in the future:
* Manually backup the originals first, or use the Batch Rename feature to copy the files to another directory
* Embed the original filenames in the XMP metadata so that they can be recovered if things go wrong (there is a preset to restore the preserved filename, the key is to preserve it first)
* Use the preview button to open up the window to double check all files, don't trust the quick preview at the bottom 100%
It is quicker to restore/recover backups than to try to rename a rename that had issues.