FIRST OCCURRENCE
addition when a structure is used.
Example ABAP Coding The following search for a regular expression finds the
two substrings "ab" and "ba" at offset 0 and offset 2, and fills the
internal table result_tab with two corresponding values. Since
the regular expression contains three subgroups, the submatches
component contains three lines. The first line of submatches
relates to the outer parenthesis, the second line relates to the first
inner parenthesis, and the third line relates to the second inner
parenthesis. The first and second lines contain the offset and length of
the first occurrence, and the third line remains undefined. The first
and third lines contain the offset and length of the second occurrence,
and the second line remains undefined.
DATA: result_tab TYPE match_result_tab.
FIND ALL OCCURRENCES OF REGEX `((ab)|(ba))`
IN 'abba'
RESULTS result_tab.
ABAP_ADDITION_6 ... SUBMATCHES s1 s2 ...
What does it do? This addition can be used only when a
regular expression is used in
pattern . The current contents of the
registry of the subgroups of the
regular expression are written to s1 , s2 , ... for the
current occurrence. The operands can be specified as follows:
As existing variables that expect a character-like type.
As an inline declaration DATA(var) ,
where a variable of type string is declared.
When ALL OCCURRENCES is used, the last occurrence is evaluated.
If there are more operands s1 , s2 , ... than subgroups, the
surplus variables of fixed length are filled with blanks and strings are
initialized. If there are fewer operands s1 , s2 , ... than
subgroups, the surplus subgroups are ignored.
Example ABAP Coding The regular expression after REGEX has two
subgroups. The search finds the substring at offset 0 with length 14.
The contents of the registry for the subgroups are "Hey" and "my".
DATA text TYPE string.
text = `Hey hey, my my, Rock and roll can never die`.
FIND REGEX `(\w+)\W+\1\W+(\w+)\W+\2`
IN text
IGNORING CASE
MATCH OFFSET DATA(moff)
MATCH LENGTH DATA(mlen)
SUBMATCHES DATA(s1) DATA(s2).
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved