Expressions

If you need only a portion of the variable, you can use the variable parsing syntax allowing to extract just the portion you need. It’s enough to enclose in round brackets the parsing directives just after the variable name, before the end % sign.

%VARIABLE(EXPRESSION)%

The parsing directives are semicolon separated and can include multiple options.

Single character extractionJust specify the position of the character to extract.

Range extractionJust specify the first and last position, separated by a minus symbol or how many characters extract from the beginning and / or the end by using the minus symbol at the beginning or at the end.

Split extraction by separatorJust indicate the split separator character followed by the index of split part to return.

Regular Expressions

For advanced extractions Regular Expressions can be used as well to extract the specific matching part(s) of the target variable value. In this case the Regular Expression needs to be enclosed in angular brackets in a similar way of the previous parsing directives.

%VARIABLE<REGEXP>%

Info

In case the Regular Expression has multiple matches they are all appended in the returned extracted value separated by a space character.

Examples

%MYVARIABLE% = 123*ABCDE*45678

%MYVARIABLE(1;4;6)% = 1*B

In the example above we got only the first, the forth and the sixth character, as indicated in the round brackets (1,4,6)

%MYVARIABLE(2-7)% = 23*ABC

In the example above we got all characters from second to seventh position (included)

%MYVARIABLE(1-3;8;13-)% = 123D678

In the example above we get the first three characters, followed by the 8th and from the thirteenth character to the end of the word

%MYVARIABLE(16)% = null value

In the example above we get the 16th character, but in the sample variable value it doesn’t exist so we get a null value.

%MYVARIABLE(-5)% = 123*A

In the example above, we get the first 5 characters.

%MYVARIABLE(‘*’,1)% = 123

In the example above we get the first section of the variable, considering the asterisk as sections separators.

%MYVARIABLE(‘*’,2)% = ABCDE

In the example above we get the second section of the variable, considering the asterisk as sections separators.

%MYVARIABLE(‘*’,3)% = 45678

In the example above we get the third section of the variable, considering the asterisk as sections separators.

%MYVARIABLE(‘*’,4)% = null value

In the example above we should get the fourth section of the variable, considering the asterisk as sections separators, but in the sample variable value it doesn’t exist so we get a null value.

%MYVARIABLE<[A-Z]+>% = ABCDE

In the example above we get the letters part by using a Regular Expression to match any number of letters in the class A-Z.

%MYVARIABLE<[0-9]{3}>% = 123 456

In the example above we get the two couples of 3 digits by using a Regular Expression to match any sequence of 3 digits.

%MYVARIABLE% = Lorem Ipsum Nr 12345 dolor sit amet

%MYVARIABLE<Nr [0-9]{5}>% = Nr 12345

In the example above we extract the Number (we imagine it is an invoice number in the middle of a bigger OCR extracted text) by using a Regular Expression to match a fixed prefix “Nr ” followed by a 5 digits number.

Previous Article

Escaping the % sign