By using the method GET_SUBMATCH
of class CL_ABAP_MATCHER
, we can get the data in the groups/subgroups.
Goal: get the token to the right of the keyword 'Type'.
DATA: lv_pattern TYPE string VALUE 'type\s+(\w+)',
lv_test TYPE string VALUE 'data lwa type mara'.
CREATE OBJECT ref_regex
EXPORTING
pattern = lv_pattern
ignore_case = c_true.
ref_regex->create_matcher(
EXPORTING
text = lv_test
RECEIVING
matcher = ref_matcher
).
ref_matcher->get_submatch(
EXPORTING
index = 0
RECEIVING
submatch = lv_smatch.
The resulting variable lv_smatch
contains the value MARA
.