segoja / mass-file-renamer

Rename files in the same way you edit text
MIT License
12 stars 2 forks source link

Which regex using? #5

Closed Turiok closed 11 months ago

Turiok commented 11 months ago

Hi and thank you for your app.

I try to use the regex find and replace for my file. I tried to capture digit to reuse it in the substitue but it seems to not working. How can I do that?

Exemple : My goal is to put a space between the "T" and the digit.

My files :

Michel Vaillant - T01 - Le grand défi.cbr
Michel Vaillant - T02 - Le pilote sans visage.cbr
Michel Vaillant - T03 - Le circuit de la peur.cbr
Michel Vaillant - T04 - Route de nuit.cbr
Michel Vaillant - T05 - Le 13 est au départ.cbr
Michel Vaillant - T06 - La trahison de Steve Warson.cbr
Michel Vaillant - T07 - Les casse-cou.cbr
Michel Vaillant - T08 - Le 8e pilote.cbr
Michel Vaillant - T09 - Le retour de Steve Warson.cbr
Michel Vaillant - T10 - L'honneur du samouraï.cbr
Michel Vaillant - T11 - Suspense à Indianapolis.cbr
Michel Vaillant - T12 - Les chevaliers de Königsfield.cbr
Michel Vaillant - T13 - Concerto pour pilotes.cbr
Michel Vaillant - T14 - Mach 1 pour Steve Warson.cbr
Michel Vaillant - T15 - Le cirque infernal.cbr
Michel Vaillant - T16 - Km 357.cbr

My find regex : T(\d+)

My replace tentative : T $1 T \1 T (?1)

I know that I could delete all characters until the numbers then add a prefix and number. But I have other files more complexe. So I would like to use capture groupe for my regex search to the replace

segoja commented 11 months ago

Hi, The app uses basic Javascript Regexp but it is limited because the "replace" string is sanitized before passing it to Regexp to prevent broken filenames and keep things simple, so capturing string fragments is not supported right now. I'll consider reworking this for the next version.

Thank you for trusting my app.

segoja commented 11 months ago

I took a deeper look and moved sanitizing to the end of the renaming loop like it should. Now find-replace works properly, allowing group capturing. There is a new release with the fix.