Jump to: navigation, search

Examples of Screening Rules

This section provides examples of screening rules.

Credit Card Number

To find text that includes a typical credit card number, you need to match a sequence of four groups of four digits, each group separated by -(hyphen):

      \d\d\d\d\-\d\d\d\d\-\d\d\d\d\-\d\d\d\d
Important
This regular expression also works without the \ (backslash) before the hyphens. However, it is better practice to write \- for the character hyphen, because the hyphen also has a special use in range expressions like [a-z].

Or if you want to allow for the possibility that some people will omit the hyphens, use? to make the hyphen optional:

      \d\d\d\d\-?\d\d\d\d\-?\d\d\d\d\-?\d\d\d\d

You could also use the repetition notation to shorten each \d\d\d\d to \d{4}.

North American Phone Number

North American phone numbers consists of ten digits, grouped into two groups of three and one of four. There are a number of ways for the groups to be separated:

      203-555-1234
      (203) 555-1234
      (203)555-1234
      203 555-1234
      203.555.1234

The following regular expression matches all of the above:

      (\d\d\d|\(\d\d\d\))[\s\.\-]?\s*\d\d\d[\-\.]\d\d\d\d


The table "Phone Number Regular Expression" analyzes this regular expression.

Phone Number Regular Expression

Symbols

Meaning

Remarks

\d\d\d

Three digits


\d\d\d|\(\d\d\d\)

Three digits, or three digits enclosed in parentheses

\ turns off the special meaning of the character (

[\s\.\-]?

Space or period or hyphen or zero

Any one of the items enclosed in square brackets, either once or not at all

\s*

Zero or more spaces


\d\d\d

Three digits


[\-\.]

Hyphen or period

Note again the need to use \

\d\d\d\d

Four digits


Telltale Words

To screen for interactions from dissatisfied customers, you might try a regular expression like the following:

      (not\s([a-z]+\s)*(pleased | satisfied)) | unhappy | complain

The first part of this expression matches not followed by zero or more words followed by pleased or satisfied; for example, not very pleased, not satisfied, not at all satisfied (but it also matches strings like can not believe how pleased I am). The rest matches the single words "unhappy" and "complain."

This page was last edited on October 12, 2018, at 22:40.
Comments or questions about this documentation? Contact us for support!