[ABAP] RegEx – String auf Datum testen

* http://www.regular-expressions.info/dates.html
DATA: lv_in TYPE string VALUE '2016-02-01'.

* mm-dd-yyyy, mm/dd/yyyy, mm.dd.yyyy, mm dd yyyy
* '^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20|21)\d\d$'

* dd-mm-yyyy, dd/mm/yyyy, dd.mm.yyyy, dd mm yyyy
* '^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$'

* yyyy-mm-dd, yyyy/mm/dd, yyyy.mm.dd, yyyy mm dd
* '^(19|20|21)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$'
DATA(matcher) = cl_abap_matcher=>create( pattern = '^(19|20|21)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$'
                                         text = lv_in
                                         ignore_case = abap_true ).

IF matcher->match( ) = abap_true.
  WRITE: / lv_in.
ENDIF.

[ABAP] RegEx – String auf White-Spaces testen

DATA: lv_txt TYPE string.
  
lv_txt = ...

* White-Spaces:
* - space
* - tab (\t)
* - carriage-return (\r)
* - newline (\n)
* - form-feed (\f)
IF abap_true = cl_abap_matcher=>create( pattern = '^\s*$'
                                        text = lv_txt
                                        ignore_case = abap_true )->match( ).
                                                    
  WRITE: / 'Der String besteht nur aus 0..n White-Spaces. Er ist im Grunde leer.'.
ELSE.
  WRITE: / 'Im String besteht nicht nur aus White-Spaces.'.
ENDIF.

[ABAP] RegEx – String auf gültige Email-Adresse prüfen

*         Übersicht TLD: https://data.iana.org/TLD/tlds-alpha-by-domain.txt
* Format Email-Adressen: https://de.wikipedia.org/wiki/E-Mail-Adresse
*    einfaches Beispiel: ^[\w\.=-]+@[\w\.-]+\.[\w]{2,18}$
*    komplexes Beispiel: ^[a-zA-Z0-9][A-Za-z0-9\.!#$%&'*+\-\/=?^_`{|}~]{0,28}[a-zA-Z0-9]@[äöü\w\.\-]+\.[\w]{2,18}$
PARAMETERS: p_email type string DEFAULT '.my.email@email.com' LOWER CASE.

IF abap_true = cl_abap_matcher=>create( pattern     = |^[a-zA-Z0-9][A-Za-z0-9.!#$%&'*+-/=?^_`\{\|\}~]\{0,28\}[a-zA-Z0-9]@[äöü\\w.-]+.[\\w]\{2,18\}$|
                                        text        = p_email
                                        ignore_case = abap_true )->match( ).
  WRITE: / 'Gültige Email'.
ELSE.
  WRITE: / 'Ungültige Email'.
ENDIF.