Regular Expressions within metadata variables

Post Reply
janwolk
Newbie
Posts: 6
Joined: Thu Sep 25, 2014 9:57 am

Regular Expressions within metadata variables

Post by janwolk »

dear all,



I'd like to capture the inital Chars from a string like "Jan Wolk" and glue it to a Ordnernummer catched out of a JDF file.



[Metadata.Text:Path="/jdf:JDF/@JobID",Dataset="Jdf",Model=JDF][Metadata.Text:Path="/jdf:JDF/jdf:AuditPool[1]/jdf:Created/@Author",Dataset="Jdf",Model="JDF",Search="[A-Z]{1}"][Metadata.Text:Path="/jdf:JDF/jdf:AuditPool[1]/jdf:Created/@Author",Dataset="Jdf",Model="JDF",Search="s[A-Z]{1}"]



this returns a string like "1234567 JW" but i need it without whitespace. I playes around with capture groups and anchors and so on, but i couldn't get rid of the whitespace...



Unfortuantely poitive lookbehinds are not supported by javascript, so are there any workarounds?



thank you in advance!!



regards, Jan
ArielRauch
Advanced member
Posts: 231
Joined: Thu Aug 07, 2014 10:04 am

Regular Expressions within metadata variables

Post by ArielRauch »

do you have access to scripting module?



Try this - have done blind - so do not accuse me on syntax errors:)



var jobID = job.getVariableAsString("[Metadata.Text:Path="/jdf:JDF/@JobID",Dataset="Jdf",Model=JDF]") ;

var author = job.getVariableAsString("[Metadata.Text:Path="/jdf:JDF/jdf:AuditPool[1]/jdf:Created/@Author",Dataset="Jdf",Model="JDF"]");



var authName = author.split(" ");

var ordNum = jobID + authName[0].left(1) + authName[1].left(1);
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Regular Expressions within metadata variables

Post by freddyp »

You should combine the Search for the first letter of the last name with "After" " "(space).



The manipulations of the string are done from top to bottom. As "Before" and "After" come first, the string is already changed by the time of the "Search" with the regular expression.



Freddy
janwolk
Newbie
Posts: 6
Joined: Thu Sep 25, 2014 9:57 am

Regular Expressions within metadata variables

Post by janwolk »

Thanks Freddy, Ariel,



[Metadata.Text:Path="/jdf:JDF/@JobID",Dataset="Jdf",Model=JDF][Metadata.Text:Path="/jdf:JDF/jdf:AuditPool[1]/jdf:Created/@Author",Dataset="Jdf",Model="JDF",After=" ",Search="[A-Z]{1}"][Metadata.Text:Path="/jdf:JDF/jdf:AuditPool[1]/jdf:Created/@Author",Dataset="Jdf",Model="JDF",Search="[A-Z]{1}"]



-->After=" "<--



did the trick. Now i get 1234567JW, thats it. Thank you very much! I didn't use the script expression, because i allways try to make it as simple as possible...



regards, Jan
Post Reply