Re-order names using Regular Expression

Bulk Rename Utility How-To's

Re-order names using Regular Expression

Postby Rinbad » Tue May 20, 2025 10:39 am

I have been a Bulk Renamer user for a good many years, but only for relatively simple tasks. I'd now like to do something more complicated which looks as if it should be possible using Regular Expressions, but I'm defeated as to how to manage and should be grateful for any help/advice. I'm using Windows 11, 24H2.

I've got a very large number of files collected over the years of newspaper references. The general form is: "Durham County Advertiser 18981130-8d (Minster electric light first time).pdf" (publication name of one or more words, sometimes including an ampersand; date in form YearMonthDay follwed by dash, page number of 1-4 digits, and letter for column reference; brief topic description in parentheses; point and extension).

I'd like to re-order all the files to put the date first, as I've come to find that the easiest way to get at the information I want (thus: "18981130-8d Durham County Advertiser (Minster electric light first time).pdf").

Before I spend any more time just getting lost, can anyone tell me if what I want to do is possible with Regular Expressions or not, please?
Rinbad
 
Posts: 3
Joined: Tue May 20, 2025 10:21 am

Re: Re-order names using Regular Expression

Postby TheGhost78 » Tue May 20, 2025 8:31 pm

Yes. Try this in RegEx (1):

Match:
(.+?) (\d{8})-(\d+[a-z]) (\((.+)\))

Replace:
\2-\3 \1 \4
TheGhost78
 
Posts: 180
Joined: Fri Jul 19, 2024 11:25 am

Re-arrange names using RegEx(1)

Postby Luuk » Tue May 20, 2025 8:37 pm

If all of your .pdfs are like the description, can use a "Match" and "Replace" something like...
^(.+ )(\d{8}-\d{1,4}[a-z] )(\(v.+\))\.pdf$
\2\1\3

This does need the checkmark for "Inc.Ext." to only rename .pdf filenames.
(It looks like I'm posting right after TheGhost78, but either one should conduct ok).
Luuk
 
Posts: 809
Joined: Fri Feb 21, 2020 10:58 pm

Re-arrange names using RegEx(1)

Postby Luuk » Wed May 21, 2025 4:05 am

Im just now realized there was a typo, the "Match" and "Replace" should have been...
^(.+ )(\d{8}-\d{1,4}[a-z] )(\(.+\))\.pdf$
\2\1\3

But it still needs the checkmark for "Inc.Ext.", unlike the one posted by TheGhost78.
Luuk
 
Posts: 809
Joined: Fri Feb 21, 2020 10:58 pm

Re: Re-order names using Regular Expression

Postby Rinbad » Wed May 21, 2025 2:07 pm

Thank you both very much indeed — that basically does it (and I understand the "replace" formulation even though I'd never have got there myself!).

There's one problem, however, with some of the newspaper names. If any of them abbreviations using a full-stop, a hyphen, or a comma in the name, those are excluded from the re-naming. (E.g. "Verordnungs- und Anzeige-Blatt 1891013-5 (Barcola distances).pdf" or "Der Gebirgsfreund, July 1901 p8 (Neue Alpenbahnen + names).pdf")

Is there any way of including such characters in the search, or do those names have to be treated manually as exceptions?

Thanks once again, and thanks in advance, I hope.
Rinbad
 
Posts: 3
Joined: Tue May 20, 2025 10:21 am

Re: Re-order names using Regular Expression

Postby TheGhost78 » Wed May 21, 2025 7:06 pm

Is it because of full stops and hyphens? The example names you gave are different to the original example.

Try:
(.+?) (\d{7,8})-(\d{1,4}[a-z]?) (\(.+\))
\2-\3 \1 \4


Der Gebirgsfreund, July 1901 p8 (Neue Alpenbahnen + names) is a completely different pattern to the original example or the one above. You can have more than one match and replace expression in RegEx by clicking the two horizontal lines to the right of Match.
TheGhost78
 
Posts: 180
Joined: Fri Jul 19, 2024 11:25 am

Re: Re-order names using Regular Expression

Postby Rinbad » Sat May 24, 2025 10:27 am

Thanks for the further reply.

Thanks to the advice from both of you, I've got where I wanted. There were indeed differences in my file-names that needed treating differently, which I was able to do by modifying the strings you advised. Also, there were just a few apparently totally aberrant names that needed treating as special cases and dealing with manually. But I'd never have got there without the help, so thanks again.
Rinbad
 
Posts: 3
Joined: Tue May 20, 2025 10:21 am


Return to How-To