Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Predicates →  rel_exp - Predicate Functions →  Predicate functions for character-like arguments 

Predicate Function, matches

This example demonstrates the predicate function matches.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA email TYPE string VALUE `abc.def@ghi.jkl`.
    cl_demo_input=>request( CHANGING field = email ).
    IF matches( val   = email
                regex = `\w+(\.\w+)*@(\w+\.)+((\l|\u){2,4})` ).
      cl_demo_output=>display( 'Format OK' ).
    ELSEIF matches(
             val   = email
             regex = `[[:alnum:],!#\$%&'\*\+/=\?\^_``\{\|}~-]+`     &
                    `(\.[[:alnum:],!#\$%&'\*\+/=\?\^_``\{\|}~-]+)*` &
                   `@[[:alnum:]-]+(\.[[:alnum:]-]+)*`              &
                    `\.([[:alpha:]]{2,})` ).
      cl_demo_output=>display( 'Syntax OK but unusual' ).
      cl_demo_output=>display( 'Wrong format!' ).


The program checks the formal correctness of an entered e-mail address by comparing it with regular expressions.

The first regular expression checks standard e-mail addresses without special characters, whereas the second regular expression performs a more lenient syntax check in accordance with RFC 822.

Even the second check, which uses a relatively simple regular expression for the example, does not always work for all e-mail addresses that could be used in accordance with RFC 822.

The program DEMO_VALIDATE_RFC_822_ADDRESS uses a regular expression taken from the Internet, which is designed to recognize all e-mail addresses allowed by RFC 822. The regular expression here was written originally for Perl and has more than 6000 characters. The program is therefore an example of how not to use regular expressions in ABAP.