Regex Expression Advice
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
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
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
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
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
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
Reply to #3:
Before consulting chatgpt, I consulted https://www.advancedrenamer.com/user_guide/v4/regular_expres ions
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.
Before consulting chatgpt, I consulted https://www.advancedrenamer.com/user_guide/v4/regular_expres ions
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.
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
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