How do I replace the last occurrence of a character

Advanced Renamer forum
#1 : 22/03-18 11:11
Ian Taylor
Ian Taylor
Posts: 4
I have multiple files, all end with -DDMMYY.JPG

I want to change this to _DDMMYY.JPG

The location of the last - changes - sometimes it's 3rd, sometimes, 4th, etc so the easiest way is to find and replace the last time the - appears, swapping it to _

How can I do this please?

Thanks,

Ian


22/03-18 11:11
#2 : 22/03-18 19:12
Stefan
Stefan
Posts: 274
Reply to #1:

FROM:
xxxx-DDMMYY.JPG
xxxx-xx xxxx-DDMMYY.JPG
xxxx-xxxx-xxxx-DDMMYY.JPG
TO:
xxxx_DDMMYY.JPG
xxxx-xx xxxx_DDMMYY.JPG
xxxx-xxxx-xxxx_DDMMYY.JPG

Plain English:
Replace very last occurrence of a hyphen to a underscore.

Try:
Replace method
https://www.advancedrenamer.com/user_guide/metho d_replace

with greedy RegEx match:
https://www.advancedrenamer.com/user_guide/regul ar_expresions


Find: (.+)-(.+)
Replace: \1_\2
[x] Use regular expressions
Apply To [Name]




 


22/03-18 19:12
#3 : 26/03-18 10:38
Ian Taylor
Ian Taylor
Posts: 4
Reply to #2:

Okay, so it seems you suggest I place some coding from the second link, into the TEXT TO BE REPLACED and REPLACE WITH boxes, therefore sidestepping the Occurence box relaying on exact positioning.

That's fine - except I am having trouble deciphering the RegEx language/expressions so, for speed;

please can someone tell me what to type into TEXT TO BE REPLACED and REPLACE WITH to change this;

FIRST-SECOND-THIRD-HOMEPAGE-110517

to this;

FIRST-SECOND-THIRD-HOMEPAGE_110517

which would word on the final hyphen on any length of filename with this end format; -DDMMYY

Thanks,

Ian


26/03-18 10:38
#4 : 26/03-18 13:12
Mark
Mark
Posts: 175
Reply to #3:

Add method - Replace

Text to be replaced: (.+)-(.+)
Replace with: \1_\2
Occurrence: All
Case sensitive: not ticked
Use regular expressions: ticked
Apply to: Name

This converts

FIRST-SECOND-THIRD-HOMEPAGE-110517

to

FIRST-SECOND-THIRD-HOMEPAGE_110517

and

xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-DDMMYY.JPG

to

xxxx-xxxx-xxxx-xxxx-xxxx-xxxx_DDMMYY.JPG

You should see the New Filename in the main screen ......


26/03-18 13:12
#5 : 26/03-18 13:26
Ian Taylor
Ian Taylor
Posts: 4
Reply to #4:
Awesome, lemme try.
Read through your posts on the process and code/expressions but I'm new to this one so having trouble deciphering the logic vs what's typed.


26/03-18 13:26
#6 : 26/03-18 15:47
Ian Taylor
Ian Taylor
Posts: 4
Reply to #4:
Worked perfectly - thank you!


26/03-18 15:47
#7 : 26/03-18 16:59
Mark
Mark
Posts: 175
Reply to #6:
Thanks to Stefan, he's the RegEx whizz :)


26/03-18 16:59