‎2009 Jan 27 3:50 PM
Hello!
I want to search in internal tables lines like I do this in where expression of sql, but thought the instrumentality of RegEx.
For example, internal table have 2 lines:
Implementations and running times
implementation language
I want to find like in SQL such string 'implrun*'
How can I do that in RegEx?
‎2009 Jan 27 4:34 PM
Is something like this what you're looking for?
TYPES: BEGIN OF ty_table,
line(80) TYPE c.
TYPES: END OF ty_table.
DATA:
l_t_table TYPE TABLE OF ty_table,
l_s_table TYPE ty_table,
l_v_regex(80) TYPE c VALUE 'impl(?:.+)run(?:.+)'.
l_s_table-line = 'Implementations and running times'.
APPEND l_s_table TO l_t_table.
l_s_table-line = 'implementation language'.
APPEND l_s_table TO l_t_table.
LOOP AT l_t_table INTO l_s_table.
FIND FIRST OCCURRENCE OF REGEX l_v_regex IN l_s_table-line IGNORING CASE.
IF sy-subrc = 0.
WRITE:/ l_s_table-line.
ENDIF.
ENDLOOP.
‎2009 Jan 27 4:34 PM
Is something like this what you're looking for?
TYPES: BEGIN OF ty_table,
line(80) TYPE c.
TYPES: END OF ty_table.
DATA:
l_t_table TYPE TABLE OF ty_table,
l_s_table TYPE ty_table,
l_v_regex(80) TYPE c VALUE 'impl(?:.+)run(?:.+)'.
l_s_table-line = 'Implementations and running times'.
APPEND l_s_table TO l_t_table.
l_s_table-line = 'implementation language'.
APPEND l_s_table TO l_t_table.
LOOP AT l_t_table INTO l_s_table.
FIND FIRST OCCURRENCE OF REGEX l_v_regex IN l_s_table-line IGNORING CASE.
IF sy-subrc = 0.
WRITE:/ l_s_table-line.
ENDIF.
ENDLOOP.
‎2009 Jan 27 4:57 PM
Jerry Coleman, Yes, that is! Great!
I know that:
"." - any symbol
"+" - 1 or more times
But what mean "(?:.+)" ?
‎2009 Jan 27 5:02 PM
(?:.+)
There are two parts to this: The *.+* means as you expect. I put parentheses around it for readability. Since I put parentheses, this causes what's matched in the regular expression to be captured in a group.
But I don't want it captured, so I use ?: to suppress the capture. This is for performance only. You could write it as:
impl(.+)run(.+)
‎2009 Jan 27 5:07 PM
‎2009 Jan 27 5:50 PM
Try this way
data: p_regex(80) TYPE c VALUE 'impl(.+)run(.+)'.
data: regex type ref to cl_abap_regex,
matcher type ref to cl_abap_matcher,
ls_result type match_result,
lt_result type match_result_tab.
condense p_regex.
create object regex
exporting
pattern = p_regex
ignore_case = ''.
* For REGEX match
matcher = cl_abap_matcher=>create(
pattern = p_regex
ignore_case = ' '
table = i_temp ). " i_temp is your internal table contains records
lt_result = matcher->find_all( ).
a®
‎2009 Jan 27 5:55 PM
‎2009 Jan 27 8:52 PM
All details of how work regular expressions can be found in [sap library - regular expressions|http://help.sap.com/abapdocu/en/ABENREGEX_SYNTAX.htm]