Show TOC Start of Content Area

Background documentation Patterns Syntax  Locate the document in its SAP Library structure

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.

This graphic is explained in the accompanying text

You can find more information about Java regular expressions at http://java.sun.com/docs/books/tutorial/essential/regex/.

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)

Example

The pattern [chw]all matches the words call, hall, and wall.

This pattern does not match any other words (for example, ball) and it does not match words in uppercase (Call, Wall, and Hall). To match both uppercase and lowercase words, use the pattern [cChHwW]all.

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

Example

The pattern \w\w\w\ matches three word characters, for example abc, SAP, A1b, 999 and 5r_.

It does not match abcd (length not equal to 3) or a c (due to white space).

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

Note

To use greedy quantifiers, you must replace X with any character or character class.

Example

The pattern \w\w\w\ is equivalent to the pattern \w{3}.

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

The composite pattern \w+ \d+ matches 123 but does not match abc.

The composite pattern \w+ \W+ does not match anything.

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.

Example

This pattern matches the following examples:

mona@

hansbosch@

Jose_Rodriguez@

       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.

Example

This pattern matches the following examples:

mona@yourcompany.org

hansbosch@company.com

Jose_Rodriguez@isp.net

       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.

Example

This pattern matches the following examples:

mona@office1.yourcompany.org

hansbosch@management.company.com

Jose_Rodriguez@server5.region3.my.isp.net

It still does not match periods before the at sign (@), for example:

nina.smith@sap.com

       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

 

End of Content Area