Examples
Extract a URL parameter value
Content: <a href="/page.jsp?kind=1¶m1=value1¶m2=value2">
Regex to extract value1 (only param1 is dynamic):
<a href="/page.jsp\?kind=1¶m1=(.*?)¶m2=value2">
Regex to extract value1 (all parameters dynamic):
<a href="/page.jsp\?.*?param1=([^&"]*)
Regex to extract value1 (where only the kind=1 links are to be taken into account):
<a href="/page.jsp\?kind=1.*?param1=([^&"]*)
Comments:
-
The first "
?" is escaped with a backslash as it is a special character. -
The first dynamic part, "
.*?" , means "any character followed by 'param1='" in this instance. The question mark "?" means that the first occurrence matched must be used. -
([^&"]*)means "any character except '&' and '"', several times". The parentheses are required to define the group. The first group ($1$in NeoLoad), refers to this matching part.
Extract a form parameter value
Content:
<form action="doit.jsp" method="post">
<input type="hidden" name="myHiddenField" value="hidden information">
Name: <input name="cn" type="text" value="filled value"><br>
<input name="myRadioField" value="val1" type="radio">Radio Value 1<br>
<input name="myRadioField" value="val2" type="radio" checked="checked">
Radio Value 2<br>
<input type="checkbox" name="myCheckbox" value="checkBoxValue" checked="checked">
A checkbox<br>
<select name="dropDownList">
<option value="val1">list choice 1
<option value="val2" selected>list choice 2
<option value="val3">list choice 3
</select><br>
<input value="Send" type="submit"><input type="reset">
</form>
The form looks like this:
Content (value in quotation marks): <input name="cn" type="text" value="filled value">
Regex: <input name="cn" type="text" value="([^"]*)"
Content (value without quotation marks): <input name="cn" type="text" value=myvalue>
Regex: <input name="cn" type="text" value=([^\s>]*)
Comment: In each case, the parentheses define the group whose value may be extracted in NeoLoad using $1$.
Advanced case: Where the web page contains several forms with text fields of the same name, the regex must contain the following:
<form action="doit.jsp" method="post">(.|\s)*?<input type=hidden name=myHiddenField value="([^"]*)"
Comments:
-
(.|\s)*?means "any character, including the new line character". "?" means that the first "<input" must be used. -
([^"]*)means "any character except the quotation mark character '"' ". The parentheses are required to define a group. The first group ($1$in NeoLoad), refers to ''(.|\s)*". However, the second group ($2$in NeoLoad) also needs to be taken into account.
The hidden field is dealt with in a similar way to a normal text field. The input type value "hidden" is substituted for "text".
Content: <input type=hidden name=myHiddenField value="hidden information" >
Regex: <input type=hidden name=myHiddenField value="([^"]*)"
Content: <input name="myRadioField" value="val2" type="radio" checked="checked" >Radio Value 2
Regex: <input name="myRadioField" value="([^"]*)" type="radio" checked="checked" >([^<\n]*)
Comments:
-
The radio button selected is the one with the checked attribute set to "checked".
-
([^"]*)means "any character except the quotation mark character '"' ". -
([^<\n]*)means "any character except '<' and the new line character ". -
The parentheses are required to define a group. The first group refers to the value and the second refers to the radio button label. Therefore, use
$1$in NeoLoad to extract the value and$2$to extract the label.
Content: <input type="checkbox" value="checkBoxValue" name="myCheckbox" checked="checked">A checkbox
Regex: <input type="checkbox" value="([^"]*)" name="myCheckbox" checked="checked">([^<\n]*)
Comments:
-
The checkbox selected is the one with the checked attribute set to "checked".
-
([^"]*)means "any character except the quotation mark character '"' ". -
([^<\n]*)means "any character except '<' and the new line character ". -
The parentheses are required to define a group. The first group refers to the value and the second refers to the checkbox label. Therefore, use
$1$in NeoLoad to extract the value and$2$to extract the label.
Content:
<select name="dropDownList">
<option value="val1">list choice 1
<option value="val2" selected>list choice 2
<option value="val3">list choice 3
</select>
Regex: <select name="dropDownList">(.|\n)*<option value="([^"]*)" selected>([^<\n]*)
Comments:
-
The list item selected is the one with the selected attribute set.
-
(.|\n)*means "any character, including the new line character". -
[^"]*)means "any character except the quotation mark character '"' ". -
([^<\n]*)means "any character except '<' and the new line character ". -
The parentheses are required to define a group. The first group in the regex is redundant; the second refers to the value and the third to the list item label. Therefore, use
$2$in NeoLoad to extract the value and$3$to extract the label.
Extract HTTP headers
Content:
Content-Type: text/html
Content-Length: 163
myHeader: myValue
Date: Thu, 03 Feb 2005 16:44:33 GMT
Server: Apache-Coyote/1.1
Regex: myHeader: (.*)
Comment: (.*) means "any character, except the newline character". The parentheses are required to define a group. Extract the header value in NeoLoad using $1$.
Extract miscellaneous values
Content: <div class ="welcomebar"> Welcome: John Doe </div>
Regex: <div class ="welcomebar"> Welcome: (\w* \w*) </div>
Comments:
-
(\w* \w*)means "two words separated by a space". The parentheses are required to define a group. The first and unique group refers to ''(\w* \w*)". Therefore, use $1$ in NeoLoad to extract both first and last names. -
Using "
(\w*) (\w*)" instead of "(\w* \w*)" may be used to extract the first and last name separately. In this case, use $1$ to extract the first name and $2$ the last name.