Remove leading and trailing spaces from all fields

Is there a way to do this in a way that works regardless of what fields are in the tracks?

Action "Format value" would require a copy for each field name.

Regexp replace

Field: _ALL

pattern: ^[\s]+|[\s]+$

Replace With:

That works great. Thanks.

Does that have some advantage over pattern: ^ +| +$ ?

Although the pseudo tag-name _ALL is introduced as a superset combination of _TAG and _FILENAME, the action "Replace using Regular Expression" cannot replace trailing spaces in the filename.
The same result is valid for the pseudo tag-name _FILENAME alone.

This special effect has been introduced due to the fact that the action "Replace using Regular Expression" is the only Mp3tag tool to change the file name extension.

Trailing spaces can be removed from the filename by respecting and saving the filename extension using the action "Replace using Regular Expression" ...
Field: _FILENAME
Expression: \s+(..*$)
Replacement: $1

Trailing spaces can be removed from the filename by ...
Convert "Tag - Tag"
Action "Format value"
Field: _FILENAME
Formatstring: $regexp(%_filename%,'\s+$',)

DD.20140323.0819.CET

Readability for one, you have to be careful with putting spaces in a regex, so using /s in a character class makes it obvious that it is intended to match a space, also \s is an abbreviation of the POSIX [:space:] class, and will match ANY white space characters, such as ASCII codes VT, TAB, FF etc. whereas a literal space only matches a space.

The stated requirement is to remove leading and trailing spaces from all fields and by implication nothing else e.g. filename. Though the exclusion you mention does mean CH's solution meets the requirement, your mention suggests the clearer solution is the one that uses _TAG instead i.e.

Replace with regular expression

Field: _TAG

pattern: ^[\s]+|[\s]+$

Replace With: <leave empty>

http://i.imgur.com/uqLtPcG.png

Thanks for the reminder. FTR, this is saying: 'Replace with regular expression' Field: _FILENAME is operative on the filename.

Yep, I took the "fields in the tracks" to be a literal requirement, as in "only affecting the metadata of the file".

OK, thanks. I personally find the space form more readable - through being more compact and literal.

Then I think the space form is the better match for the stated requirement. Plus presumably those other white space characters won't show in Mp3tag like space characters, and I'd prefer a solution that removed just the characters that look like space characters. If any of the others did end up if my fields, I'd want to see them and deal with them and their cause directly.

Should better be described as:

'Replace with regular expression'
Pseudo Field _FILENAME is operative on the filename including fileextension.

DD.20140324.1708.CET

Ah yes, good point. One must remember that (int this special case, Action type 'Replace with regular expression') _FILENAME does not correspond to %_FILENAME%, but to %_FILENAME_EXT%.

Florian, how about resolving this by (just in this Action type, 'Replace with regular expression') adding _FILENAME_EXT and removing _FILENAME on this list of allowed 'fields'* and make the dialog change existing _FILENAME to _FILENAME_EXT. Obviously for compatibility with user configs, the program would have to continue to accept _FILENAME stored in actions.

  • I previously wrote "The stated requirement is to remove leading and trailing spaces from all fields and by implication nothing else e.g. filename." but now I see that the Action dialogue box classifies the filename as a field. Misleading!