Using Regular Expressions with NetTracker


NetTracker is constructed so that regular expressions can be used in one of two ways. You can use regular expressions when setting many of NetTracker’s options. You can also use them when setting up filters on data presented in a standard summary.

For instance, NetTracker uses regular expressions heavily in both its browser and platform options. The following regular expression defines which user agents in your log files will be classified as the Microsoft Internet Explorer Web browser:

^Mozilla/.*MSIE (\d+\.)

(To see this regular expression in NetTracker, view a Web profile, click the Options tab, click Browsers under Visitors in the left-hand panel, click Microsoft Internet Explorer in the list, and then click User Agents.)

If a user agent in your log file matches the regular expression above, then the browser used by that user will be listed as Microsoft Internet Explorer in your Browser Summary.

By breaking down the regular expression, you can see exactly what NetTracker is looking for.

Expression
Meaning
^
The string must start with the characters that follow (Mozilla/)
Mozilla/
The characters that must be at the beginning of the string
.*
There can be any number of characters (including none) between Mozilla/ and the text that follows (MSIE)
MSIE
The next string of characters that must be present (including a space after the E)
( )
The contents of the parentheses will be considered a single unit
\d
Matches any decimal digit
+
Modifies the \d so NetTracker will look for one or more digits
\.
Tells NetTracker to stop looking for digits when it finds a period. The backslash (\) tells NetTracker to match a period instead of using the period (.) as a metacharacter

The above expression will match the following strings:

Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.5; Windows 98)

Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)

Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; AIT; DigExt)

Because the regular expression includes information about the browser version number (\d+\.), if you have selected the Append the version number check box for the browser the first two strings above will appear as Microsoft Internet Explorer 4 and the last string will appear as Microsoft Internet Explorer 5. (For details on selecting the Append the version number check box, see "Creating a Browser" and "Editing the Browsers".)

You can also use the That match the pattern filter with a regular expression as a filter when filtering a standard summary. For instance, you could filter a Page Summary so it only contained data for visitors who were using NetBSD, FreeBSD, or OpenBSD, but not BSDI. You would need to enter That match the pattern .*BSD$ as the complete platform filter. The period and asterisk (.*) allows a match on any characters that precede BSD in the string, but because of the dollar sign ($), the string must end in BSD.