Question about regex replace function for variables

Started by banzai, October 14, 2023, 06:55:53 PM

Previous topic - Next topic

banzai

Hi there,

I'm trying to use a regex to replace some string with itself or leave it out (and then use this expression in the renamer with "Text and Variables"):

{File.Name|regexp:(-[0-9])$//!,\1,}

If the filename ends with "-" and one digit, the new crafted name shall also get the same postfix.
But I did not manage to reference the capture group, tried \1 and $1. Is there any other way to reference the capture group?

Thanks.

Ciao,  banzai

Tveloso

If you want to refer to a group in a Renamer Replace Text step, it would be \1.

For example, I regularly use a Renamer Preset to replace the FileNme Component nnnn(Edited) with whatever nnnn was, and "_v0" (which fits my versioning scheme):

Renamer_Replace1.png

The \1 reference to the group in that patten is entered in the with: field in the Replace Text step:

Renamer_Replace2.png
--Tony

banzai

Thanks for your reply.
I guess I could switch my approach and use Replace Text Step, but as the original filename will be completely replaced, this would need some more changes.

For now I helped myself with a workaround cause in the current case, the length of the postfix is known:
{File.Name|regexp:(-[0-9])$//!,{File.Name|substrr:0,2},}