Hi,
this might not be a sound flow question but given the level of coding workflow gods that hang out here I figured someone might know!
Trying to remove everything that appears before "_" using batch rename.There could be any number of characters that appear before the _. Im 90% sure this is possible using regular expressions but I after quite a bit of googling I'm getting nowhere.
Thanks in advance
- Raphael Sepulveda @raphaelsepulveda2024-02-15 17:48:27.977Z
@Jack_Green, this can be done in several ways but let's start with this simple pattern:
.*_
This will match anything before the last underscore including the underscore itself.
When used in Batch Rename with regex turned on, a track namedsongName_GTR
will become justGTR
.Hopefully, that does it but let me know if it mishaves.
Btw, I like using the following website for testing regex in a visual way: https://regexr.com/
Christian Scheuer @chrscheuer2024-02-15 23:45:00.421Z
This should also do it, and even more immediately:
for(let oldTrackName of Array.from(sf.ui.proTools.selectedTrackNames)) { let newTrackName = oldTrackName.split('_')[0]; sf.app.proTools.renameTrack({ oldName: oldTrackName, newName: newTrackName, }); }
Christian Scheuer @chrscheuer2024-02-15 23:49:42.715Z
Here it is as a regex:
for(let oldTrackName of Array.from(sf.ui.proTools.selectedTrackNames)) { let newTrackName = oldTrackName.match(/^(.*)_/)[1]; //[1] means take the first captured group - the group is designated by the parentheses sf.app.proTools.renameTrack({ oldName: oldTrackName, newName: newTrackName, }); }
- In reply tochrscheuer⬆:
Jack Green @Jack_Green
Thanks a bunch.
This actually works great even without using batch rename.
I changed the [0] to [1] as it was keeping the stuff before the underscore rather than the stuff after.
1 small issue is if there are 2 underscores it keeps what is between them. Is there a way to say keep [1] + [2] + however many there are? in other words just remove the [0] element?
Thanks again for all your help :)
Christian Scheuer @chrscheuer2024-02-16 17:24:35.737Z
Ah, I'm sorry I misunderstood - I thought you wanted to keep everything before the '_'.
Here's another version that keeps everything after the first underscore:
for(let oldTrackName of Array.from(sf.ui.proTools.selectedTrackNames)) { let newTrackName = oldTrackName.split('_').slice(1).join('_'); sf.app.proTools.renameTrack({ oldName: oldTrackName, newName: newTrackName, }); }