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

The 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 e-mailaddress that has been entered by comparing it with regular expressions.

Whilst the first regular expression checks standard e-mail adresses without special characters, the second regular expression performs a more lenient syntax check according to 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 which were possible according to RFC 822.

The DEMO_VALIDATE_RFC_822_ADDRESS program uses a regular expression taken from the Internet, which should actually recognize all e-mail addresses allowed by RFC 822. The regular expression there was originally written for perl and no longer consists of more than 6000 characters. The program therefore serves as an example of how not to use regular expressions in ABAP.