Regex folder match not working with script

Advanced Renamer forum
#1 : 12/04-17 00:02
Ed
Ed
Posts: 2
Script Method panel not working. I'm just trying to get it to return the year part using a simple regex pattern. But it returns a string concantenated with original string separated by two ".." dots. Can't figure out what i'm doing wrong?

==================
Original folder name (other folders follow same format):
==================
2015.11.20 - Orlando - Downtown - E Colonial Dr

==================
Using only one Script Method:
==================
var patt = /\d{4}[.]/;
var yearPart = patt.exec(item.newBasename);

return yearPart;

================
Output:
================
2015..20 - Orlando - Downtown - E Colonial Dr

This output looks wrong to me. I was expecting to see only 2015 and not what appeared. What am I missing?

Also, I don't know if this is related but weirdly whenever I try to add a new script block it remembers the last script that had been used. Is there some way to turn this off?


12/04-17 00:02 - edited 12/04-17 01:11
#2 : 12/04-17 08:18
G. Lambany
G. Lambany
Posts: 185
Reply to #1:
Well, for the sake of correcting your script, here it is:

var patt = /(\d{4}).+/;
var yearPart = patt.exec(item.newBasename);
return yearPart[1];

You needed to capture a group in your expression with () and use it with an array position on the result array yearPart[1]. Also, [.] means matching one character, of any kind. .+ means matching any characters, so it would fit better with what you are trying to achieve.

But quite honestly, this wasn't needed to be done with a script, could've very well be done with "remove" method, from position 5 onward, or "replace" with the same kind of regex..

hope that helps,
cheers


12/04-17 08:18
#3 : 12/04-17 19:53
Ed
Ed
Posts: 2
Reply to #2:

Thanks for the Regex clarification. It really helped. What I needed was to return the Year and the period.

===============
Regex Fixed
===============
/(\d{4})\./

===============
Expected Return
===============
2015.

===============
Actual Return
===============
2015..20 - Orlando - Downtown - E Colonial Dr

As you can see from this screen capture. All my returns are messed up.

http://www.intermediastrategy.com/advancedrenam er.png

As a test to see if this is a program bug, I changed the script to just return "hello" and the same error appears. Is there some sort of setting I need change or clear the internal program cache?

http://www.intermediastrategy.com/advancedrenam erBug.png


12/04-17 19:53 - edited 12/04-17 20:39
#4 : 12/04-17 22:51
G. Lambany
G. Lambany
Posts: 185
Reply to #3:
I must admit, its an interesting bug...

Only affect folders... works fine on files.

To go around it, put your script method to "name and extension"

cheers


12/04-17 22:51