Using Regular Expressions in Rules

A regular expression is a combination of characters and operators that specifies a pattern. You can use regular expressions with certain attributes in rules to match patterns in messages.

You can test regular expressions using the Test Regular Expressions tool. After creating an expression, in the Attributes section, select "matches the regular expression" in the If the Attribute menu, then:

A new window containing the expression opens.

NOTE: KANA Response rules use regular expressions that are compatible with Perl 5. For more information about using regular expressions, see a Perl 5 reference guide.

Reserved characters

Use the following reserved characters to indicate the pattern that you are trying to match.

Character

Description

Example

/

Encloses a regular expression

/productA|productB/

|

The OR operator

productA|productB

()

Encloses a group

(\w+)

[]

Defines a character range

[a-e]

{}

Defines the number times the preceding character or
character group repeats

{4}

^

Begins with the character range that follows

^ab

$

Matches only at the end of the text

html$

*

Matches the preceding character or character group 0 or more times

^z.*e$

+

Matches the preceding character or character group 1 or more times

cat+

?

Matches the preceding character or character group 0 or 1 time

htm(l)?

.

Matches any character, including white space

.*mycompany\.com

\

Escapes other reserved characters, including itself

\(800\)

 

NOTE: When using the | operator, make sure that there are always characters preceding and following the operator. Otherwise, the attribute will always be true.

Modifiers

Use the following modifiers to specify how KANA Response should handle the specified attribute.

Character

Description

i

Ignore case

m

Treat string as multiple lines

s

Treat string as a single line

x

Ignore white space

Important!  Using an x option in an expression does not mean that the white space is ignored in the text. It means that white space (including comments) is ignored in the regular expression. For example, the expression '/[A-Z]   [0-9]   {6}   [0-9X]/xsi' is equivalent to '/[A-Z][0-9]{6}[0-9X]/si'. This x option is useful for spacing out the regular expression so that it's more readable.


Learn about rules and rule groups.

How do I create a rule?

Can I view an example of a rule using regular expressions?

Are there any tips on using rules?