Patterns Syntax

Use

Bounced Mail Framework (BMF) patterns are Java regular expressions (Java RegEx).

To create or understand a pattern, you need to know the syntax of Java regular expressions.

The basics of creating simple patterns are described here.

Basic Regular Expression Constructors

Characters

Syntax Description

x

Character x

\\

Backslash (\)

\t

Tab

\n

New line

\.

Period (.)

Character Classes

Syntax Description

[abc]

a, b, or c (simple class)

[^abc]

Any character except a, b, or c (negation)

[a-zA-Z]

a through z, or A through Z, inclusive (range)

Predefined Character Classes

Syntax Description

.

Any character

\d

A digit (0-9)

\D

A nondigit - all characters except (0-9)

\s

A white space (for example, space, tab, new line)

\S

A nonwhite space - all characters except white spaces

\w

A word character - all characters from a-z, A-Z, all digits and underscore (_)

\W

A nonword character - all characters except word characters

Greedy Quantifiers

Syntax Description

X?

X, once or no times

X*

X, zero or more times

X+

X, one or more times

X{n}

X, exactly n times

X{n,}

X, at least n times

X{n,m}

X, at least n but not more than m times

Composite Patterns

You can write several patterns on one line if you separate them with spaces.

In this case, to match the composite patterns, each sub pattern must match.

Example

In this example, you create a pattern for matching mail addresses.

  1. Look at the following pattern:

    (\w+)@

    The w+ indicates that one or more word characters must appear. This must be followed by an at sign (@).

    The parentheses () are not required here, but they divide the expression into groups and this can be useful when you need to change a logical part of the pattern.

  2. Extend the pattern to the following:

    (\w+)@(\w+\.)(\w+)

    The (\w+\.) group is similar, but expects a period (.) to follow.

    The period is escaped using a backslash (\) because the period character itself matches any character.

    The (\w+) group is already explained in the previous step.

  3. Extend the pattern to the following:

    (\w+)@(\w+\.)(\w+)(\.\w+)*

    The (\.\w+) group matches a period (.) followed by one or more word characters.

    The asterisk (*) denotes that the preceding character or group can occur zero or more times.

    Since the parentheses () denote a group and the asterisk (*) applies to the whole group, the pattern matches a period (.) followed by one or more word characters, and it matches that combination zero or more times.

  4. Use this pattern to match any e-mail address:

    (\w+)(\.\w+)*@(\w+\.)(\w+)(\.\w+)*

    You can easily change this pattern to include the addresses you need.

    For example, if you need to match all e-mail addresses from the domain company.com, change the pattern to:

    (\w+)(\.\w+)*@company\.com