Copy link to clipboard
Copied
Hello,
I try to acheive regex matching with group but it won't work.
And what i read is in java it can't forward...but here is a way to do this ?
I am learning java, but i have good basics in python. Here is what I will have written in python :
re.fullmatch(r"(?P<prod>\w\d\w)_(?P<ep>\d{3})_(?P<sht>(\d{3}_\w)|(\d{3}))_(?P<tsk>(\w{5})|(\w{5}\S\w))_(?P<ver>\d{2}).(?P<ext>\w{3})",Is for matching fileName like this :
PRO_100_010_A_BGCOL_01.psd
PRO_100_010_A_BGCOL_A_01.psd
PRO_100_010_BGCOL_01.psd
PRO_100_010_BGCOL_A_01.psd
you can test-it, it work :
Even if i try to match (with no forward) only one :
PRO_100_010_A_BGCOL_01.psd
var str = "PRO_100_010_A_BGCOL_01.psd"
var matchA = /(?<prod>\w{3})_(?<ep>\d{3})_(?<sht>\d{3}_\w)_(?<tsk>\w{5})_(?<ver>\w{2}).(?<ext>\w{3})/g;
var groups = str.match(matchA).groups;
alert(groups.prod);
alert(groups.ep);
alert(groups.sht);i've got error ?
regards,
Seems like the named groups are not supported by Extendscript. Something like the following should work to check if the string matches or not
var str = "PRO_100_010_A_BGCOL_01.psd"
var matchA = /(\w{3})_(\d{3})_(\d{3}_\w)_(\w{5})_(\w{2}).(\w{3})/g;
var groups = str.match(matchA)
alert(groups)
If you want to get the match in the group, try the following code
var str = "PRO_100_010_A_BGCOL_01.psd"
var reg = new RegExp(/(\w{3})_(\d{3})_(\d{3}_\w)_(\w{5})_(\w{2}).(\w{3})/g);
var m = reg.exec(str)
...
Copy link to clipboard
Copied
Ok, try this way, but error :
//var documents = app.activeDocument;
//var docName = app.activeDocument.name;
//var docPath = app.activeDocument.path.fsName;
var docName = "F2R_405_017_COLOR_01.psd"
var matchA = /(?<prod>\w{3})_(?<ep>\d{3})_(?<sht>\d{3}_\w)_(?<tsk>\w{5})_(?<ver>\w{2}).(?<ext>\w{3})/g;
var groups = docName.match(new RegExp(matchA, "g").groups;
var ep = groups.ep;
alert(ep)
Copy link to clipboard
Copied
Seems like the named groups are not supported by Extendscript. Something like the following should work to check if the string matches or not
var str = "PRO_100_010_A_BGCOL_01.psd"
var matchA = /(\w{3})_(\d{3})_(\d{3}_\w)_(\w{5})_(\w{2}).(\w{3})/g;
var groups = str.match(matchA)
alert(groups)
If you want to get the match in the group, try the following code
var str = "PRO_100_010_A_BGCOL_01.psd"
var reg = new RegExp(/(\w{3})_(\d{3})_(\d{3}_\w)_(\w{5})_(\w{2}).(\w{3})/g);
var m = reg.exec(str)
alert(m[1]);
alert(m[2]);
-Manan
Copy link to clipboard
Copied
Thank you, i'll try with (a|b) (match a or b) if it works
Copy link to clipboard
Copied
Nice ! @Manan Joshi
Thank you again 😉
I figured out :
var match = new RegExp(/(\w\d\w)_(\d{3})_(\d{3}_\w|\d{3})_(\w{5}|\w{5}\S\w)_(\d{2}).(\w{3})/g);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more