User Guide

Server behavior techniques 287
Next, the searchPattern tag searches the document more precisely than the quickSearch tag
and extracts parameter values from the participant code. The search patterns specify where to
search (the
whereToSearch attribute) with a series of searchPattern tags that contain specific
patterns. These patterns can use simple strings or regular expressions. The previous example code
is an ASP directive, so the
whereToSearch="directive" specification and a regular expression
identifies the directive and extracts the parameters, as shown in the following example:
<quickSearch>Response.Write</quickSearch>
<searchPatterns whereToSearch="directive">
<searchPattern paramNames="rs,new__url">
/if\s*\((\w+)\.EOF\)\s*Response\.Redirect\("([^\r\n]*)"\)/i
</searchPattern>
</searchPatterns>
The search string is defined as a regular expression by starting and ending with a slash (/) and is
followed by
i, which means that it is not case-sensitive. Within the regular expression, special
characters such as parentheses () and periods (.) are escaped by preceding them with a backslash
(\). The two parameters
rs and new__url are extracted from the string by using parenthetical
subexpressions (the parameters must be enclosed in parentheses). In this example, they are
indicated by
(\w+) and ([^\r\n]*): These values correspond to the regular expression values
that are normally returned by
$1 and $2.
Optional search patterns There might be cases where you want to identify a participant even
if some parameters are not found. You might have a participant that stores some optional
information such as a telephone number. For such an example, you could use the following
ASP code:
<% //address block
LNAME = "joe";
FNAME = "smith";
PHONE = "123-4567";
%>
You could use the following search patterns:
<quickSearch>address</quickSearch>
<searchPatterns whereToSearch="directive">
<searchPattern paramNames="lname">/LNAME\s*=\s*"([^\r\n]*)"/i¬
</searchPattern>
<searchPattern paramNames="fname">/FNAME\s*=\s*"([^\r\n]*)"/i¬
</searchPattern>
<searchPattern paramNames="phone">/PHONE\s*=\s*"([^\r\n]*)"/i¬
</searchPattern>
</searchPatterns>
In the previous example, the telephone number must be specified. However, you can make
the telephone number optional, by adding the isOptional attribute, as shown in the
following example:
<quickSearch>address</quickSearch>
<searchPatterns whereToSearch="directive">
<searchPattern paramNames="lname">/LNAME\s*=\s*"([^\r\n]*)"/i¬
</searchPattern>
<searchPattern paramNames="fname">/FNAME\s*=\s*"([^\r\n]*)"/i¬
</searchPattern>
<searchPattern paramNames="phone" isOptional="true">¬
/PHONE\s*=\s*"([^\r\n]*)"/i
</searchPattern>
</searchPatterns>