Try this.
// https://resource.dopus.com/t/move-selected-files-to-sub-folder-named-by-parts-of-the-first-selected-files-name/42706
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false;
if (tab.selected_files.count == 0) return;
cmd.SetDestTab(tab);
cmd.RunCommand('Copy MOVE CREATEFOLDER=' + tab.selected_files(0).name_stem.replace(/.*_(\d\d\d\d).*/, '$1'));
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>42706</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/move-selected-files-to-sub-folder-named-by-parts-of-the-first-selected-files-name/42706</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction> cmd.deselect = false;</instruction>
<instruction />
<instruction> if (tab.selected_files.count == 0) return;</instruction>
<instruction />
<instruction> cmd.SetDestTab(tab);</instruction>
<instruction> cmd.RunCommand('Copy MOVE CREATEFOLDER=' + tab.selected_files(0).name_stem.replace(/.*_(\d\d\d\d).*/, '$1'));</instruction>
<instruction>}</instruction>
</function>
</button>