Code: Alles auswählen.
DATA: matcher TYPE REF TO cl_abap_matcher,
match TYPE c LENGTH 1,
matchr TYPE match_result,
offset TYPE i,
length TYPE i,
oref TYPE REF TO cx_root,
text TYPE string.
PARAMETERS p_pat(80) LOWER CASE.
PARAMETERS p_txt(80) LOWER CASE DEFAULT text-001.
START-OF-SELECTION.
TRY.
matcher = cl_abap_matcher=>create( pattern = p_pat
ignore_case = 'X'
text = p_txt
simple_regex = ' ' ).
CATCH cx_sy_invalid_regex INTO oref.
text = oref->get_text( ).
ENDTRY.
IF NOT matcher IS INITIAL.
match = matcher->find_next( ).
ENDIF.
IF NOT text IS INITIAL.
WRITE: / text.
ELSE.
WRITE: / 'Match:', match COLOR COL_GROUP.
IF match = 'X'.
matchr = matcher->get_match( ).
DO.
offset = matcher->get_offset( index = 0 ).
length = matcher->get_length( index = 0 ).
WRITE: / 'Offset:', offset.
WRITE: 'Length:', length.
match = matcher->replace_found( text-spc ).
CALL METHOD matcher->find_next
RECEIVING
success = match
EXCEPTIONS
OTHERS = 1.
IF sy-subrc > 0 OR match = space.
EXIT.
ENDIF.
ENDDO.
write: / 'Text:', matcher->text.
ENDIF.
ENDIF.