Regular expression block helps to search, split or to replace operations on strings.
Fully expanded, the Regular expression block shows the following properties:
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.
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).
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 a field to be used in the parsed text.
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 dropdown specifies the regex method (Match, Split or Replace).
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.
Splits an input string into an array of substrings at the positions defined by the pattern specified in the expression as the delimiter.
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 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.
The “Use occur.” allows you to specify which occurrence to use in case you have multiple matches. As with other similar building blocks in Leaptest 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 .
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.
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.Author: June 6, 2016. ,