using script and item path

Advanced Renamer forum
#1 : 13/11-23 21:01
pipja
Posts: 2
Hi guys, I have a script below that I think should work, but I'm getting uncaught post script errors 'unterminated character class' and I don't know what's wrong.
Here's the script:

function (index, item) {
var regex = new RegExp("^.*\\([^\\]+)\\[^\\]+$", "gi");
var matches = regex.match(item.path);
return matches[1]+ '_' + item.filename;
}

basically the script tries to grab the parent folder name of the file and prefix the filename.

Help is very much appreciated, thank you :).
#2 : 17/11-23 09:32
Kim Jensen
Administrator
Posts: 932
Reply to #1:
I think it is the [^\\] part it doesn't like.
#3 : 26/11-23 07:32
pipja
Posts: 2
Reply to #2:
Too hard to figure out so I gave up XD