I have file names like the following:
SEM_VSE_SKINSHARPS_555001881_181002_1559_37072093.DAT SEM_VSE_SECURITY_555001881_181002_1559_37072093.DAT SEM_VSE_MEDICALCONDEMERGENCIES_555001881_181002_1559_37072093.DAT SEM_REASONS_555001881_181002_1414_37072093.DAT SEM_PSE_NPI_SECURITY_555001881_181002_1412_37072093.DAT
Any help is greatly appreciated.
This is a good use case for regular expressions. For example,
var oldFileName = 'SEM_VSE_SKINSHARPS_555001881_181002_1559_37072093.DAT', newFileName; newFileName = oldFileName.replace(/[_0-9]+(?=.DAT$)/, ''); // SEM_VSE_SKINSHARPS.DAT
This says to replace as many characters as it can in the set
0-9, with the requirement that the replaced portion must be followed by
.DAT and the end of the string.
If you want to strip the
.DAT, as well, use
/[_0-9]+.DAT$/ as the regular expression instead of the one above.