[ABAP] In internen Tabellen suchen

Teilstrings in String suchen

DATA(lv_string) = |ABAP_ABAP|.
DATA(lv_search) = |BA|.

FIND ALL OCCURRENCES OF lv_search
  IN lv_string
  IGNORING CASE             " case insensitive
  RESULTS DATA(it_results). " TYPE match_result_tab

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / substring( val = lv_string off = <r>-offset len = <r>-length ).
  ENDLOOP.
ENDIF.

Variante 2 (erstes Auftreten eines String in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

* erstes Auftreten des Teilstrings 'SERVER_' ermitteln, case-sensitive Suche
FIND FIRST OCCURRENCE OF SUBSTRING 'SERVER_'
  IN TABLE it_strings
  RESPECTING CASE          " case-sensitive
  MATCH LINE DATA(idx)     " Index
  MATCH OFFSET DATA(off)   " Offset
  MATCH LENGTH DATA(len).  " Länge

IF sy-subrc = 0.
  WRITE: / off.
  WRITE: / len.
  WRITE: / it_strings[ idx ].
ENDIF.

Variante 3 (alle gefundenen Strings in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

FIND ALL OCCURRENCES OF SUBSTRING 'SERVER_'
  IN TABLE it_strings
  RESPECTING CASE           " case-sensitive
  RESULTS DATA(it_results). " Ausgabetabelle

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / it_strings[ <r>-line ], <r>-offset, <r>-length.
  ENDLOOP.
ENDIF.

Variante 4 (RegEx: alle gefundenen Strings in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

* Alle Auftreten der Suchbegriffe NAME und TIMEOUT
FIND ALL OCCURRENCES OF REGEX 'NAME|TIMEOUT'
  IN TABLE it_strings
  RESPECTING CASE           " case-sensitive
  RESULTS DATA(it_results). " Ausgabetabelle

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / it_strings[ <r>-line ], <r>-offset, <r>-length.
  ENDLOOP.
ENDIF.

Links

[JavaScript] RegEx verwenden

Variante 1

let str = '123456';
let regex = /^(\d{6})?$/;

// RegEx testen
// Besp: String muss aus 6 Zahlen bestehen
if (regex.test(str))
{
    console.log('match');
}
else
{
    console.log('no match');
}

Variante 2

let str = '123456';

// RegEx testen
// Besp: String muss aus 6 Zahlen bestehen
if (/^(\d{6})?$/.test(str))
{
    console.log('match');
}
else
{
    console.log('no match');
}

[ABAP] RegEx – Hausnummern und Straßennamen aus String filtern

* https://regex101.com/

* Straße des 17. Juni 100/a
* Hauptstrasse 22-1
* Kleiner Weg 3
* Berliner Strasse 22 - 24 A
* Hermann-Weise-Weg 11b

DATA: lv_in TYPE string VALUE 'Straße des 17. Juni 100/a'.

* suchen nach Hausnummern in String
DATA(matcher) = cl_abap_matcher=>create( pattern = '\s[0-9]{1,}[\/ \-0-9a-zA-Z]*'
                                         text = lv_in
                                         ignore_case = abap_true ).

* Tabelle mit Suchergebnissen
DATA(it_matches) = matcher->find_all( ).

IF NOT it_matches IS INITIAL.
* der letzte Eintrag sollte die Hausnummer sein
  DATA(lv_last_entry) = it_matches[ lines( it_matches ) ].

* Straße
  WRITE: / substring( val = lv_in
                      off = 0
                      len = lv_last_entry-offset ).

* Hausnummer
  WRITE: / substring( val = lv_in
                      off = lv_last_entry-offset + 1
                      len = lv_last_entry-length - 1 ).
ENDIF.

[ABAP] RegEx – Postleitzahl (PLZ) und Ort aus String filtern

* https://regex101.com/

* 12345 Berlin
* D12345 Berlin
* D-12345 Berlin
* D 12345 Berlin
* d12345 Berlin
* d-12345 Berlin
* d 12345 Berlin
* D-12345 Berlin-Tegel
* D-12345 Berlin (Bezirk Tegel)

DATA: lv_in TYPE string VALUE 'D-12345 Berlin (Bezirk Tegel)'.

DATA(matcher) = cl_abap_matcher=>create( pattern = '^(?:[Dd][- ]?)?\d{5}\s'
                                         text = lv_in
                                         ignore_case = abap_true ).

DATA(it_matches) = matcher->find_all( ).

IF NOT it_matches IS INITIAL.
* der erste Eintrag sollte die PLZ sein
  DATA(lv_plz) = it_matches[ 1 ].

* PLZ
  WRITE: / substring( val = lv_in
                      off = lv_plz-offset
                      len = lv_plz-length - 1 ).

* Ort
  WRITE: / substring( val = lv_in
                      off = lv_plz-length
                      len = strlen( lv_in ) - lv_plz-length ).
ENDIF.

[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.