Regular Expression

The Regular expression block is used to search, split, or replace operations on strings. Fully expanded, the Regular expression block shows the following properties:

Regular-expression

The Block Header (“Regular expression”)

The green input connector in the header is used to trigger the block to start executing.

The green output connector in the header triggers when the result of the regular expression has been found.

The title of the block (“Regular expression”) can be changed by double-clicking on it and typing in a new title.

Text

The text you would like to parse. It can be typed in the field, fed as input from the previous block, inserted as a token (added below).

Text fields

Fields that enable the use of external values in the parsed text.

To use the value of an added field, right-click the text field above and select “Insert token” and then insert this field’s name.

Add field

Add a field to be used in the parsed text.

Expression

The “Expression” field holds the actual regex . To see how to write a regular expression and to check how it works you can refer to this website.

Method

Method drop-down specifies the regex method (Match, Split or Replace).

Match method

Searches an input string for a substring that matches a regular expression pattern and returns the occurrences. When you select the match method, the entire input string is matched against the rule/pattern outlined in the Expression field.

Split method

Splits an input string into an array of substrings at the positions defined by the pattern specified in the expression as the delimiter.

Replace method

In a specified input string, replaces strings that match a regular expression pattern with a specified replacement string. You define 2 expressions: one to match a part of the input string, and one to insert the matched sub string into.

Please see the examples of the three methods in use in this blog article.

The result

The text result of the regular expression. If you choose to use all occurrences every occurrence will have an individual result. You can use it as input to the following blocks.

Use Occurrence

The “Use occur.” allows you to specify which occurrence to use in case you have multiple matches. As with other similar building blocks in LEAPWORK you can specify the exact occurrence to use or select “All” to iterate all matching results. If you select “All” then the top green connector will be triggered for every result found .

Count

The number of results (occurrences) found. Even if you choose one specific occurrence in Use Occurrence above the count will show you the number of all of them.

Not found

If a match is found for any of the methods, the green connector at the top will be triggered. Otherwise the “Not found” connector will be triggered. This is typically used to branch execution flow or to explicitly fail a case by linking it to a Fail block.

 

Updated April 20th 2018.