Solved regular expressions - Replacing the first x number of charac

January 4, 2014 at 13:33:26
Specs: windows
Hello- I did some searching but have come up blank (could be my searching skills)

I am trying to clean up my music files and run across files names like

2-02 songname.mp3
2-04 songname.mp3
and so on.

Would anyone like to help me with a regular expression to replace the first # of characters in a file name with whatever artist name. Instead of specifying that I want to replace 2-02 I would just like to say replace the first 4 characters with Artist.

to change
2-02 songname.mp3
2-04 songname.mp3
Artist - Songname.mp3

I have around 10k files to rename so this would figuratively save my life!


See More: regular expressions - Replacing the first x number of charac

Report •

January 4, 2014 at 14:04:24
✔ Best Answer
There are multiple ways to construct the regex. Here are 3 options.



s/^[^ ]+/Artist/



Report •

January 4, 2014 at 18:07:12
I'm not sure where r/e even comes into the picture as you've described. If it's always replacing the first 4 bytes, then r/e is overkill. You can get the matching files with:
dir /b "?-?? *.mp3". So my big question is: where does the value for "Artist" come from? (I assume you don't want the literal "Artist", but the actual artist). Is it the directory name or what? It's stored in the mp3 files, but it's unicode, so...

message edited by nbrane

Report •

Related Solutions

Ask Question