Moving groups of files to a folder of matching name

Similar to what is discussed in this post - https://www.advancedrenamer.com/forum_thread?forum_id=12092

I am looking to move files into folder that matches the name of the file minus the last 8 characters of the file name. I am using the script provided in the above thread but it says null for the folder name. I am not sure how to resolve it. I am hoping it can move them to a folder if it exists or make the folder if needed.
Reply to #1:

Hi JB,

Without knowing what your filenames look like, a script should do what you want. Try this:

folder = item.name.match(/^.*(?=.{8})/);
item.newPath=item.path+ folder ;

Batch mode should remain on "Rename", not "Move" or "Copy". Be sure to change the columns view in the file list to show you the "New Path" so you can make sure beforehand that the files will go where you mean to aim them. ("Options / Columns" on the menu)
EDIT: And always remember there's Undo Batch if you have trouble. END EDIT

Good luck, let us know how it goes.
Best,
DF
Reply to #2:
Hello DF,

Thank you, that works perfectly. I was trying to use the $ instead of the ^ as well as some other errors as I can tell from the script you provided.

Thank you so much.
Reply to #3:

Any time, my friend...