Regex renames

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
oblivion
Posts: 142
Joined: 13 Apr 2011 11:35

Regex renames

Post by oblivion »

I had an odd (and slightly self-induced) problem -- I accidentally activated a backup program that had been configured for a laptop I'm upgrading from on a new machine without protecting the older backup.

Didn't lose any data, but everything got moved to an archive folder with everything renamed to the original filename with the then current date and timestamp appended in brackets.

So the problem was to create a search and replace style of rename that would convert something like

filename (dd-mm-yy, hh-mm-ss).ext

back to filename.ext

and I wanted to create something I could reuse rather than solving the problem for each specific instance of (dd-mm-yy, hh-mm-ss)
I figured fairly quickly I'd only be able to do this using regex but all my experimenting (using preview to check the results of my experiments) failed miserably, mostly either creating no output filename at all, or leaving the source intact.

I can't claim great expertise with regex in general (probably a large part of the problem is my own overestimation of my own ability to ascend a steep learning curve in seconds) but is there such a thing as an XYplorer-specific cheat sheet for the basics? In particular, if the syntax of an XYplorer search and replace needs non-obvious characters to be escaped?

It also occurs to me -- only now -- that I might have completely failed to work out how to store and reuse the part of the filename before the " (" bit, which might mean that the versions that produced blank output weren't as wrong as all that after all... :oops: :whistle:

Anyway, the laptop I was migrating to and which had all the problems currently only exists as a disk image while the supplier gets their act together on the replacement front, so I have a few days to get better at this :biggrin:
-- bests, Tim

...This space unintentionally left blank.

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Regex renames

Post by highend »

Code: Select all

^(.+?)((?:[ ]*?)\(\d{2}-\d{2}-\d{2}, \d{2}-\d{2}-\d{2}\))(\..+?)$ > $1$3
XYplorer specific basics? It's a simple regular expression. They work exactly the same for all tools that use the VB6 regex engine...
One of my scripts helped you out? Please donate via Paypal

oblivion
Posts: 142
Joined: 13 Apr 2011 11:35

Re: Regex renames

Post by oblivion »

Thanks!

I'm not sure I use any other tools that use the VB6 regex engine. I have some (very generic) regex notes I've used in the past for other things, but they didn't help me get this right.

I guess I might find documentation for it somewhere on the Microsoft website? I'll go look.
-- bests, Tim

...This space unintentionally left blank.

Post Reply