#1 2025-08-15 00:11

thej0ker
Member
Registered: 2025-08-14
Posts: 3

Regex: Rename using part of the name twice

I'm after renaming a file from, i know the '/' shouldnt exist in a filename but for the sake of the argument please help

wibble/rss/acg

to

heros/rss_acg/acg


the 'acg' part changes ie it can be anything and any length but always at the same place of the name and needs to end up at the same place in the result twice.

the 'rss' and 'rss_' is the same every time

the first part can be a simple replace 'wibble/rss' for 'heros/rss_'

but then i get stuck ...

Last edited by thej0ker (2025-08-15 00:17)

Offline

#2 2025-08-15 00:16

thej0ker
Member
Registered: 2025-08-14
Posts: 3

Re: Regex: Rename using part of the name twice

Oh I forgot to say the maybe more '/' earlier in the name..

Offline

#3 2025-08-18 13:20

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,496

Re: Regex: Rename using part of the name twice

It looks likes you are trying to duplicate the part after the last delimiter so that it also appears before the last delimiter. Is that correct?

You can try this Regular Expressions rule: Replace expression "(.*)/(.*?)\Z" with "$1_$2/$2".

Input filename: wibble/rss/acg

Output filename: wibble/rss_acg/acg

Perhaps few real examples could better demonstrate what you are trying to do.

Offline

#4 2025-08-18 18:23

thej0ker
Member
Registered: 2025-08-14
Posts: 3

Re: Regex: Rename using part of the name twice

I forgot to add the the input needs to find wibble first as it could be anything so examples are

Input
wibble/rss/acg
fred
bob/bob
wibble/rss/qwerty

Output
wibble/rss_acq/acg
wibble/rss_qwerty/qwerty

With the two in the middle being ignored..

I have tried
^wibble.*(.*)/(.*?)\Z

$1_$2/$2

Help please

Offline

#5 2025-08-18 23:40

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,496

Re: Regex: Rename using part of the name twice

Replace expression "\A(wibble/.*)/(.*?)\Z" with "$1_$2/$2".

Offline

Board footer

Powered by FluxBB