Page 1 of 1
RegEx: how do I get the length of match group?
Posted: 2025-07-28 23:51:47
by regex_student
I have files with variable length names which I would like to rename them to a fixed length
from
to
Ant Renamer Regular expressions renaming has a link to
TRegExpr manual that menthions MatchLen property for Groups, but I couldn't find how to get that info and use it in the New name field for Regular expressions renaming
any help and hint on how to do this would be appreciated
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-29 07:15:00
by antp
Hi,
Unfortunately you cannot access that info from the program, that's something for the code itself.
I'm not sure it is so simple to do padding with regular expression (you can maybe find some more info on internet by searching that, but I recall that it was not so simple in one pass).
However what you can do is add a fixed number of zeros in front (e.g. 4) and then using regular expression limit to keep only last x characters.
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-29 09:30:34
by regex_student
Hi,
since the info are available in the code, is it possible to add new list (similar to multi-string replace) to the Regular expression renaming where user can add modifications to the captured group? in this case, I would add action to make the capture group 1 to have at least 5 chars and left pad char '0' when the group is less than 5 chars
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-30 06:51:57
by antp
It would be possible, sure, but a lot of things could be done on groups, in this case you want to make padding but there is an infinite number of possible actions

I could try to make a list of useful actions, but all that would be a major feature to add, and my to-do list is already so much bigger than my available time for maintaining the software, so it is unlikely that I would have time for that unfortunately.
In the meantime, in this case there is a workaround requiring two different actions (inserting zeroes and then limiting the number of characters).
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-30 07:08:05
by regex_student
I have been thinking about how to do the two step actions you had suggested, just haven't figured out the exact expression to limit or trim the number of digits due the actual filenames have various random length strings before and after the numbers
something like
Code: Select all
wolf_tdi3.blahtlba.1.plowya.txt
al34bast.23.lote.est1883.txt
kingston5400.492.ddr5-cuughy.txt
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-30 10:06:50
by regex_student
antp wrote: 2025-07-30 06:51:57
It would be possible, sure, but a lot of things could be done on groups, in this case you want to make padding but there is an infinite number of possible actions

I could try to make a list of useful actions, but all that would be a major feature to add, and my to-do list is already so much bigger than my available time for maintaining the software, so it is unlikely that I would have time for that unfortunately.
In the meantime, in this case there is a workaround requiring two different actions (inserting zeroes and then limiting the number of characters).
understood. would be good if the new feature would allow me to do something similar to C string format. in this case, printf like %05u on the captured group
Re: RegEx: how do I get the length of match group?
Posted: 2025-07-30 17:57:25
by antp
That could be an idea, indeed.
For the second step to remove extra zeroes, if you add always 4 zeroes, you can then match (.+)\.0*(\d{4})\.(.+) and then keep only that group to discard the useless zeroes: \1\2\3 as final name.
To be tested, I assume it would work but I didn't try

Inserting the zeroes for the first step could use a similar expression.