Regex Expression Advice

Advanced Renamer forum
#1 : 06/03-25 04:31
Henry
Posts: 8
Hi,

I am trying to rename from "Letter to the president 0341234" to "0341234 - Letter to the president"
The first part "letter to the president" contains all letters, no digits.

I consulted with chatgpt which suggested this:
Find = ^(.*?)\s*(\d+)\.pdf$
Replace = \2 - \1.pdf

but Advanced Renamer failed to change.

What needs to be corrected to the regex?

Thanks
#2 : 06/03-25 05:49
Delta Foxtrot
Posts: 436
Reply to #1:

Hi Henry,

That expression worked for me, as long as the "Apply to:" field is set to "Name and extension" (and of course regular expressions are set on). I have "Occurrence:" set to All, but 1st probably works too.

Best,
DF
#3 : 06/03-25 14:51
Miguel
Posts: 178
Reply to #1:
Hi Henry. It doesn't work for me either. Make the following changes.

REPLACE: ^(.*?)\s*(\d+)
REPLACE WITH: \2 - \1

Use regular expression cheked.


Miguel
#4 : 06/03-25 16:36
Henry
Posts: 8
Reply to #3:

Before consulting chatgpt, I consulted https://www.advancedrenamer.com/user_guide/v4/re gular_expresions

I thought I could use \w or \W thus
Find = ^(\w*)(\d+)

which (\w*) would group the "letter to the president".

Guess it is time to hit youtube again.
#5 : 07/03-25 02:36
Delta Foxtrot
Posts: 436
Reply to #4:

Henry,

Your expression won't work because the character class \w does not include spaces, so the first space in the filename kills the match. The \w also includes numbers 0-9, so even if you included spaces in the first match it would still gobble up all the numbers at the end, so there would be no "\2" to find.

This works:
Replace: ^([A-Za-z\s]+)(\d+)
With: \2 - \1
(regex yes, apply to name, occurrence all or 1st),

So does Miguel's expression with the same parameters, but so does the original ChatGPT expression (with apply to: Name and extension, as long as your file is a .pdf).

You don't need youtube, you just need to apply what's here.

Best,
DF