List replace after certain characters

Advanced Renamer forum
#1 : 10/02-23 13:24
Hunny Oylia
Hunny Oylia
Posts: 2
Hello,
I try to add color codes to lots of files following this:

ORIGINAL FILE NAMES:
123-222330-blue-34.jpg
123-222335-blue-34.jpg
123-222334-night-blue-34.jpg
123-222333-night-blue-34.jpg
123-222335-blue-denim-34.jpg
123-222336-blue-denim-34.jpg

CHANGE INTO:
123-222330-117-blue-34.jpg
123-222335-117-blue-34.jpg
123-222334-226-night-blue-34.jpg
123-222333-226-night-blue-34.jpg
123-222335-331-blue-denim-34.jpg
123-222336-331-blue-denim-34.jpg


When I use replace list, I get files like "123-222334-night-117-blue-34.jpg", I didn't find the right method yet. I hope somebody can help me!


10/02-23 13:24
#2 : 10/02-23 16:14
David Lee
David Lee
Posts: 1125
Simple! Only add a colour code if "-<colour->" is both preceded and followed by numerical digits.

List Replace using regular expressions...

Replace: \d\K(-blue-)(?=\d) with: -117\1

(=?\d) is a "lookahead", which is an instruction to match the preceding pattern only if it is followed by a digit (\d).

Unfortunately the corresponding "lookbehind" (?<=\d) is not available in the regex flavour used by Advanced Renamer (PCRE) so we have to use a workaround:

"\d(-blue-)" will match a digit followed by "-blue-" and the character "\K" is an instruction to exclude any preceding matched characters from the final result.

Placing a pattern in parentheses ie (-blue-) means that any resulting match will be saved in a numbered variable (\1 in this case) , which can be recalled in the replacement string.


10/02-23 16:14
#3 : 13/02-23 12:09
Hunny Oylia
Hunny Oylia
Posts: 2
Reply to #2:
Thank you very much!!
I'm new to Advanced Renamer and didn't know all the characters yet.

The list replace worked now!


13/02-23 12:09