RegEx Remove from FileName


#1

I wish to remove xyz or 256 and everything AFTER it in a filename. Can someone help me?

Thanks,
David


#2

2 possible ways:

a ) Rename your file with the content of your existing ID3-Tags like %ARTIST% - %ALBUM% - %TRACK% -%TITLE% and the Converter ALT-1

b ) Write an Action for the field _FILENAME to remove "xyz or 256 and everything AFTER it in a filename"


#3

Sorry I wasn't more specific. I am looking for someone to help me with the Regex for the action you described in option b.

Thanks in advance,
David


#4

If you really want remove "xyz or 256 and everything AFTER it in a filename", you could use this:

Actiontype "Replace with Regular Expression"
(I'm not sure about the text, because I don't use the english version...)
Field: _FILENAME
Regular Expression: (xyz.)|(256.)
Replace matches with:.mp3
[ ]Case-sensitive

This regular expression looks for:
the string: xyz
and any other character: .
occuring 0 ore more times: *
or: |
the string: 256
and any other character: .
occuring 0 ore more times: *

and replace it with
the string: .mp3

If you have a filename like
01-Artistname-Title of the 256 most fantastic songs.mp3
you get
01-Artistname-Title of the .mp3 <--- have a look at the space after the word "the "!

If you have a filename like
01-Artistname-Title (xyz and something else).mp3
you get
01-Artistname-Title (.mp3 <--- have a look at the brace left from .mp3!

If you have a filename like
256-Artistname-Title (xyz and something else).ogg
you get
.mp3 <--- 256 and everything else will be replaced by the fixed .mp3!

You see, it isn't that easy with your definition "xyz or 256 and everything AFTER it in a filename".
Even if you say: the extension isn't part of a filename, you still have the problem with spaces, braces and the position of "xyz" and "256".

Maybe it would be better, if you could give us some REAL examples of your filenames.

I hope, this will give you starting point. :sunglasses:


#5

Thanks! This was exactly what I needed. I appreciate the time you spent in your extensive explanation. I learned something new and hopefully others will learn from this example as well.

I used to put tons of junk into my filenames but often started with the bitrate encoded. By doing this for 256 and 320 I will be able to remove most of the garbage then tag from my old filenames.

I didn't realize that it would truncate the file extension, as well, so you saved me much confusion there as well.

Cheers,
David


#6

Is this

(\s320.*)

The way to handle that leading space?

Do I use the parens if I'm only searching one string?

Thanks,
David


#7

Yes: \s looks for a "white space".
And if you wanna match the space AND open parenthesis:
(\s(320.*)

In your case, the paranthesis are not really necessary. They just group the possible matches together.

(xyz.)|(256.) would give you a group1 and group2. This way, you could replace each group with different content or do something with the first group and something else with the second group. :wink: