Help needed with RegEx rename

I searched through the internet and asked in forums and LLMs to find an answer to my question, but never got a working solution:

I want to add a number right after a group selector: \11 to move my files into folders based on the decade of the file name.

This won't work, as it will recognize the group 11 instead of group 1 + the character 1.

In "regular" regEx I could go around with {1}1, or with named groups which is not supported. Could you give me some advice?

input: 20250507_082135.jpg
expected output: **2020--2029** /2025/2025-05/2025-05-07/2025-05-07 08-21-35.jpg

First step: getting the year into groups: (\d{3})(\d) => 202, 5
substitute: \1\2 => returns 2025, as expected
assumption, substitute: \10--\19 or \1&0--\1&9 or \1"0"--\1"9", etc. should return **2020--2029**

As I want to move the files in the appropriate folder while renaming it, it would not be possible to do a 2-step solution, where I rename like \1*1 and remove the * in a second attempt.

Btw: why DO is using its own interpretation of regEx instead of the regular one, which also accepts $1 as a group selector or named groups like (?pattern).?

1 Like

\11 works fine by itself here. It will insert the first capture group, then a literal 1.

We aren't doing that. We're using one of the standard regex libraries and syntaxes.

There isn't a single regex standard, unfortunately. There are lots of flavours, all with slight differences, the same as with every other program and language that uses regex. You've probably just not used regex in enough things to realise the one you're used to isn't the same one used everywhere.

Regex is more a concept than a concrete syntax, although the different flavours have a lot of overlap and it doesn't take long to adapt from one to another.

1 Like

Looks okay here.

1 Like

Thanks for the screenshot. Found my mistake: I used "Regular Expressions + Find And Replace" instead of "Regular Expressions". It works now as intended.

Thank you!

kind of related. Is it possible to created Named capturing groups like (?...) ... some of my regex become very complex.

I don't think so.

1 Like

Once they become that complex, it may be worth considering using a rename script instead of a (single) regex.

1 Like

Yeah, that a good point. Need to dig into scripting then. Thanks for the advice.

Yes. Bonus: That regex flavor uses $ for its capture groups :slight_smile:

And no named capture groups neither (JScript or VB Script doesn't change this, it does not exists in those two scripting languages, at least not until a more recent version of javascript).