Working With Subexpressions

Applies to LoadComplete 4.97, last modified on May 20, 2019

In LoadComplete, you use regular expressions to find data in requests and server responses in user scenarios.

Requests and responses can contain a large amount of complex data, and it may be difficult to specify a regular expression that will match the data you need exactly. In this case, you can use subexpressions to specify the needed data.

For example, a server response contains a field whose value you want to extract. A regular expression may not specify the field value precisely. In this case, you can define a regular expression that matches a larger data segment in the response and then use a subexpression to find the value you need.

Using Subexpressions

To point the piece of data for a subexpression to match, you use parentheses in the regular expressions. In other words, parentheses are placeholders for subexpressions in the entire regular expression string:

name="MyHiddenField".*?\s*?value="(.*?)"\s

You specify the needed subexpression in the $number format, where number is the subexpression position. $1 corresponds to the first subexpression; $2 - to the second one, and so on. $0 indicates data returned by the entire regular expression.

Note: LoadComplete allows specifying up to 9 sub-expressions inside a regular expression.

If the regular expression should include the parentheses symbols literally, use a backslash ( \ ) before parentheses:

… name="MyHiddenField".*?\s*?value="(.*?)"\s*>Text \(some more text\) …
Using Subexpressions in Data Correlation Rules

Data correlation rules in LoadComplete search for dynamic parameters in requests and responses.

You can use subexpressions in correlation rules to –

  • Specify the name of the variable that LoadComplete will use to store the value of the correlated dynamic parameter.

    Using subexpressions to specify variable names

    Click the image to enlarge it.

    A subexpression in the Variable Name text box will get the needed piece of data that the regular expression specified in the Find names and extra attributes | Expression text box matches.

  • Specify the part of the regular expression that LoadComplete will use to search for the data to be extracted:

    Using subexpressions to specify the data to extract

    Click the image to enlarge it.

    A subexpression in the Select from responses | Expression text box will get the needed piece of data that the regular expression specified in the Find names and extract attributes | Expression text box matches.

  • Specify the part of the regular expression or the path that LoadComplete will use to search for the data to be replaced:

    Using subexpressions to specify the data to replace

    Click the image to enlarge it.

    A subexpression in the Replace in requests | Expression text box will get the needed piece of data that the regular expression specified in the Select from responses | Expression text box matches.

  • Specify the piece of data LoadComplete will extract from responses or that LoadComplete will replace in requests:

    Using subexpressions to specify a piece of data to extract or replace

    Click the image to enlarge it.

    A subexpression in the Attributes column will get the needed piece of data that the regular expression specified in the Select from responses | Expression or Replace in requests | Expression text box matches.

See Also

Regular Expressions Syntax
About Data Selectors
About Data Replacers
Data Correlation

Highlight search results