Im my Java application, users can specify how to name their files from a series of metadata fields. i.e
%artist% - %album% - %disctotal%
One option would be to use a parser generator.
ANTLR is one such tool for Java. If you're a novice at creating grammars, you'll find the grammar IDE ANTLRWorks useful.