Need help with a big regex script

A swapping-ground for Regular Expression syntax

Need help with a big regex script

Postby argitoth » Tue Aug 13, 2013 7:06 am

here's what I need to happen:

from A_01 to 10_01_A
from A_02 to 11_01_A
from A_03 to 12_01_A
from A_04 to 01_02_A
from A_05 to 02_02_A
from A_06 to 03_02_A
from A_07 to 04_02_A
from A_08 to 05_02_A
from A_09 to 06_02_A
from A_10 to 07_02_A
from A_11 to 08_02_A
from A_12 to 09_02_A
from A_13 to 10_02_A
from A_14 to 11_02_A
from A_15 to 12_02_A

There's actually 104 of these... yes I need 104 rules in one RegEx. Is this possible? I mean, I bet there's probably a way to write some logic so that the RegEx can handle the numbering system I created, so then there'd only be 4 rules needed. But I bet that is a lot more complex. To keep it simple I could just write the same code 104 times in slightly different ways to accommodate my numbering system. If it is way to encumbering to write 104 rules in one RegEx, I don't mind writing in one RegEx rule at a time 104 times.

Just in case I'll tell you what the numbering system is if you want to take a stab at writing the logic, and I don't even know if it's possible, can RegEx even incorporate math?:

-example file name: D_01_loud_rele_01

-every file begins with a capital letter, an underscore, and then two numbers. example: D_01. Ignore everything after that in the file name.

-There are 4 possible letters that the file name begins with. A, D, E, G. The _01 goes up to _25 in the case of filenames beginning with D. E goes up to _29.

A_01 to A_25
D_01 to D_25
E_01 to E_29
G_01 to G_25

In the example of D_01, it needs to be replaced by 03_02
03 = octave number (goes from 1 to 4)
02 = note number (goes from 1 to 12)

once the note number reaches 12, the octave number gets +1 and note number goes to 1

example:
10_01
11_01
12_01
01_02
02_02
03_02

A starts at 10_01 (note 10, octave 1)
D starts at 03_02 (note 3, octave 2)
E start at 01_01 (note 1, octave 1)
G starts at 08_02 (note 8, octave 2)

example:
A_01 to D_25 would become 10_01_A to 10_03_A
D_01 to D_25 would become 03_02_D to 03_04_D
E_01 to D_25 would become 01_01_E to 05_03_E
G_01 to D_25 would become 08_02_G to 08_04_G
argitoth
 
Posts: 4
Joined: Tue Aug 13, 2013 5:57 am

Re: Need help with a big regex script

Postby Stefan » Tue Aug 13, 2013 9:35 am

I guess you would need a script to do the math.


But if you already knew the renaming pairs:
from A_01 to 10_01_A
from A_02 to 11_01_A
from A_03 to 12_01_A


then you can write them to a text file
A_01.ext|10_01_A.ext
A_02.ext|11_01_A.ext
A_03.ext|12_01_A.ext

and use "Renaming From A Text File".

 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Need help with a big regex script

Postby argitoth » Tue Aug 13, 2013 6:11 pm

Can "Renaming from a text file" run RegEx? Is that RegEx code you wrote there? If not, then it's not useful in this case.

Edit: I know how the text file works, that's not where I'm confused. You wrote .ext at the end. IS that RegEx or just a way of saying "the extension"? btw. I have almost 1800 files to rename. The most simplest thing would just be to use a RegEx to Match all files that begin with E_01 and make them...

01_01_E_rest-of-the-file-name-goes-here.wav

...then I can edit the RegEx to fit A_01 to A_25 and so on... but I don't know RegEx code yet. Trying to learn.

Edit2: Actually, what I could do is use a text editor that has RegEx capability to edit a renaming text list... what text editor would you recommend?

Edit3: Ok, I think I figured out some RegEx code:

match: (E_01)_(.*?)_(.*?)_(.*?)\.(.+)
replace: \1_\2_\3_\4.\5|01_01_E_\2_\3_\4.\5

example input: E_01_loud_rele_01.wav
example output: E_01_loud_rele_01.wav|01_01_E_loud_rele_01.wav
argitoth
 
Posts: 4
Joined: Tue Aug 13, 2013 5:57 am


Return to Regular Expressions


cron