8.1 Creating Filters with Regular Expressions for General_AsciiLogRX

Some Knowledge Scripts enable you to use regular expressions to define include and exclude filters for pattern-matching against the text being evaluated. Depending on the Knowledge Script you are working with, you may be able to use regular expression include and exclude filters when you are setting job properties or you may be able to maintain your search criteria independent of the Knowledge Script parameters in a separate filter file. You may also be able to use regular expression modifiers to further refine your filtering.

For example, if your include filter is replic.* and you specify the modifier i to make the search case-insensitive, the regular expression contains the wildcard (.) and repeat (*) special characters, indicating you want to find strings that start with replic followed by any string of characters. Messages containing either replication or replicated are captured.

The format is the same for the exclude filter. For example, to find log entries that do not start with the string success, the exclude filter might look like this:

^success.*

If you are only searching for included strings, you can leave the exclude filter blank. If you want to retrieve all messages in the log in a given interval, you can specify .* for the include filter and leave the exclude filter blank.

8.1.1 Using Special Characters

The following special characters can be used in regular expressions:

Use This Character

For This Purpose

.

Wildcard for any one character

*

Repeat zero or more occurrences

^

Beginning of the line

\$

End of the line

\

Escape the next meta-character

|

Alternate matches

[ ]

Any character in the class set. You can specify individual characters or ranges.

( )

Grouping characters. For example, you can specify (a|b|c) to indicate a match with a, or b, or c.

+

Quantifier indicating one or more occurrences

?

Quantifier indicating zero or one occurrence

{n}

Quantifier indicating exactly n occurrence

\w

A word character (alphanumeric plus _)

\s

A white-space character

\d

A digit character

8.1.2 Using Regular Expression Modifiers

In addition to the special characters you can use in creating the regular expression, there are a number of modifiers that can be used to modify how pattern-matching is handled. Valid modifiers include:

Modifier

Description

c

Complements the search list

g

Matches globally as many times as possible

i

Makes the search case-insensitive

m

Treats the string as multiple lines

o

Interpolates variables only once

s

Treats the regular expression string as a single long line

x

Allows for regular expression extensions

For additional information about writing regular expressions, see your Perl documentation or other regular expression resources.