Help with dynamic find and replace button

Hi, Im trying to make a button which does this rename command.

Now im trying to do this with dialog. With some examples on forum I have this

@nodeselect @set brace1={ @set brace2=} @set Position={dlgstring|Enter character position to replace...} @set Replace={dlgstring|Replace with...} Rename REGEXP PATTERN "^(.{$brace1}{$position}{$brace2}).(.*)" TO "\1{$Replace}\2" AUTORENAME TYPE=files

So this ask me which position to find and what to replace with.
Though I noticed, it ignores the spaces at the beginning and the end.

For example if I run this on 01.Rename.txt and enter position 2 to replace with space dash space it returns 01-Rename.txt instead of 01 - Rename.txt

Could someone help me out with those spaces? thanks

@set will trim spaces off the start/end, but luckily there's no need for @set to be used with the thing you don't want to be trimmed, so you can do this:

@nodeselect @set brace1={ @set brace2=} @set position={dlgstring|Enter character position to replace...} Rename REGEXP PATTERN "^(.{$brace1}{$position}{$brace2}).(.*)" TO "\1{dlgstring|Replace with...}\2" AUTORENAME TYPE=files

Great! Thanks Leo. :thumbsup:

How would I modify this to address multiple characters. Say I want 2nd and 3rd character. I tried this old: ^(.{2-3}).(.*) new: \1x\2 but that didn't work.

Hi Leo.
If I run your code on multiple files it brings up the second dialog box for every file. Is there any workaround to this?

I'm not sure why it would do that, but these days I would write a script rather than fight with @set and {dlgstring} if they aren't doing what you want with a basic command.

That will let you apply more complex/clever logic for the rename as well.