Page 1 of 1

regex: Lookbehind not supported?

Posted: Tue Sep 16, 2014 9:46 am
by Joerg Schober
Hi,

trying to add hierarchy. For this, I try to extract "SA" from jobname

D_SA_1040.pdf



The used regex is

(?<=[a-zA-Z]{1}_)[a-zA-Z]{2}



It does not work. Is lookbehind supported by Switch?



Kind regards,

Jörg

regex: Lookbehind not supported?

Posted: Tue Sep 16, 2014 2:24 pm
by freddyp
Lookbehind is indeed not supported.



I assume you are using this regular expression in the Search field of the Job.NameProper variable. There Switch only matches the first occurrence, so [a-zA-z]{2} would also return SA.



Freddy

regex: Lookbehind not supported?

Posted: Tue Sep 16, 2014 2:43 pm
by Joerg Schober
Thanks Freddy for the reply.



There are also other filenames that are different (SE_MM_1804, ...), so the regex needed in production enviroment is

(?<=[a-zA-Z]{1,2}_)[a-zA-Z]{2}



How could i solve this issue. Is a script expression possible?

Supports javascript lookbehind (with variable length)?

It seems most languages only supports lookbehind (if they supports) with fixes length.



Kind regards,

Jörg



regex: Lookbehind not supported?

Posted: Tue Sep 16, 2014 6:54 pm
by ArielRauch
If I understand correctly you want to extract the different segments of the name. Should not be a a problem in a script expression.



Nameproper.split("-")



Or did I misunderstand you

regex: Lookbehind not supported?

Posted: Tue Sep 16, 2014 7:19 pm
by dkelly
Joerg Schober wrote: try to extract "SA" from jobname

D_SA_1040.pdf


A script expression to retrieve "SA" part would be:



job.getNameProper().split("_")[1];