I am trying to extract the last 3 characters from a pattern using below REGEX, which is working in online REGEX tester but not working in RUTA.
Below is the code that I have tried in online REGEX builder: https://regex101.com/r/2JN9a5/1
Below is code that I have tried in RUTA:
"(?i)\\b([QI]{2}|[Q])[\\s || -]{0,2}[0-9]{5,}[\\s || -]{0,2}\\K[A-Z]{3}\\b" -> EntityType;
Q-123456-PAD
Exp O/p: PAD
Input : QI-1234567-PLB
PLB
If it is Pega
then try this
PACKAGE uima.ruta.example;
DECLARE VarA;
DECLARE VarB;
DECLARE VarC;
W{REGEXP("Q|QI") -> MARK(VarA)}
(WS|"-")?
NUM{REGEXP(".{1,7}")-> MARK(VarB)}
(WS|"-")?
W{REGEXP(".{1,3}")-> MARK(VarC),MARK(EntityType,5,5), UNMARK(VarA), UNMARK(VarB), UNMARK(VarC)};
Explanation:-
(WS|"-")?
:- Space or "-". You can remove the ?
if one of that is fixed.
NUM{REGEXP(".{1,7}")
:- Number between 1 to 7.
W{REGEXP(".{1,3}")
:- Capital alphabet 1 to 3.
MARK(EntityType,5,5)
:- marking only the 5th row. i.e W{REGEXP(".{1,3}")
. If you mark MARK(EntityType,1,5)
then it will return Q-123456-PAD
.