‎2015 Aug 07 5:30 AM
Hi,
I'm trying to get a regex that will work in ABAP/4 that will scan the contents of an internal table are return the list of matching rows.
so it's a FIND ALL OCCURENCES OF REGEX l_patt IN TABLE lt_cvs IN CHARACTER MODE RESULTS lt_results.
The contents of the table are: (this is the CVS table from the Time Evaluation B2 Cluster)
1 A002AO1 02 293.50 YSNH
2 A002AO2 01 203.50 YSNH
3 B002AO1 01E8D0211 1203.00 YSNH
4 B002AO1 02E8D0211 293.50 YSNH
5 B002AO2 01E8D0211 203.50 YSNH
6 A002AO1 01 0.00 YSTD
7 A002AO1 02 0.00 YSTD
8 A002AO2 01 85.00 YSTD
9 B002AO1 01E8D0211 0.00 YSTD
10 B002AO1 02E8D0211 0.00 YSTD
11 B002AO2 01E8D0211 85.00 YSTD
12 A002AO1 01 0.00 YSTH
13 A002AO1 02 0.00 YSTH
14 A002AO2 01 203.50 YSTH
15 B002AO1 01E8D0211 0.00 YSTH
16 B002AO1 02E8D0211 0.00 YSTH
17 B002AO2 01E8D0211 203.50 YSTH
I want to find the rows with the string "YSTH" or "YSTD", and also only find those with the first character equalling "A". This means I expect to only find rows 6, 7, 8 and 12, 13, 14.
I've gone to www.regexr.com and have gotten the pattern "(A00.*?(YSTD|YSTH))" to return the rows I want (If I have just "A" in the first argument then it will return rows 9, 10, 11, 15, 16, 17 as well because the letter "A" is in the string as well) I've tried using "^" but I'm not sure how this might work.
I've tried using the DEMO_REGEX_TOY but it does not seem to work. The ".*?" is not recognised in ABAP - it short dumps.
Any ideas or suggestions would be appreciated.
Thanks!
‎2015 Aug 07 6:00 AM
Hi,
please check this:
REPORT ztestregex.
CONSTANTS: c_regex TYPE string VALUE '^A(.)*(YSTH|YSTD)'.
PARAMETERS: p_text TYPE string.
START-OF-SELECTION.
FIND REGEX c_regex IN p_text.
IF sy-subrc EQ 0.
WRITE: /1 c_regex,
'found in ' COLOR COL_POSITIVE,
p_text.
ELSE.
WRITE: /1 c_regex,
'not found in ' COLOR COL_NEGATIVE,
p_text.
ENDIF.
Regards,
Klaus
‎2015 Aug 07 6:00 AM
Hi,
please check this:
REPORT ztestregex.
CONSTANTS: c_regex TYPE string VALUE '^A(.)*(YSTH|YSTD)'.
PARAMETERS: p_text TYPE string.
START-OF-SELECTION.
FIND REGEX c_regex IN p_text.
IF sy-subrc EQ 0.
WRITE: /1 c_regex,
'found in ' COLOR COL_POSITIVE,
p_text.
ELSE.
WRITE: /1 c_regex,
'not found in ' COLOR COL_NEGATIVE,
p_text.
ENDIF.
Regards,
Klaus
‎2015 Aug 07 6:05 AM