2008 Mar 31 1:26 PM
Hi,
has anybody an idea why the FIND REGEX statement and the regex class delivers different results when searching for
^\*
in
****
I try to find every place with an asterisk as first sign of the line.
The FIND statement
DATA gv_string TYPE string.
DATA gv_pattern TYPE string.
DATA gt_match_result TYPE match_result_tab.
gv_string = '****'.
gv_pattern = '^\*'.
FIND ALL OCCURRENCES OF REGEX gv_pattern
IN gv_string
RESULTS gt_match_result.
returns one hit as expected. But the class cl_abap_regex and cl_abap_matcher returns four hits in this example:
DATA gv_string TYPE string.
DATA gv_pattern TYPE string.
DATA gt_match_result2 TYPE match_result_tab.
DATA gx_regex TYPE REF TO cl_abap_regex.
DATA gx_matcher TYPE REF TO cl_abap_matcher.
gv_string = '****'.
gv_pattern = '^\*'.
TRY.
CREATE OBJECT gx_regex
EXPORTING
pattern = gv_pattern.
CATCH cx_sy_regex .
BREAK-POINT.
EXIT.
ENDTRY.
TRY.
CREATE OBJECT gx_matcher
EXPORTING
regex = gx_regex
text = gv_string.
CATCH cx_sy_matcher .
BREAK-POINT.
EXIT.
ENDTRY.
gt_match_result2 = gx_matcher->find_all( ).
BREAK-POINT.
Looks like the class doesn't consider the start of line symbol (^). Is there an error in my implementation?
Any help is appreciated.
Matthias
Hi,
has anybody an idea why the FIND REGEX statement and the regex class delivers different results when searching for
^\*
in
****
I try to find every place with an asterisk as first sign of the line.
The FIND statement
DATA gv_string TYPE string.
DATA gv_pattern TYPE string.
DATA gt_match_result TYPE match_result_tab.
gv_string = '****'.
gv_pattern = '^\*'.
FIND ALL OCCURRENCES OF REGEX gv_pattern
IN gv_string
RESULTS gt_match_result.
returns one hit as expected. But the class cl_abap_regex and cl_abap_matcher returns four hits in this example:
DATA gv_string TYPE string.
DATA gv_pattern TYPE string.
DATA gt_match_result2 TYPE match_result_tab.
DATA gx_regex TYPE REF TO cl_abap_regex.
DATA gx_matcher TYPE REF TO cl_abap_matcher.
gv_string = '****'.
gv_pattern = '^\*'.
TRY.
CREATE OBJECT gx_regex
EXPORTING
pattern = gv_pattern.
CATCH cx_sy_regex .
BREAK-POINT.
EXIT.
ENDTRY.
TRY.
CREATE OBJECT gx_matcher
EXPORTING
regex = gx_regex
text = gv_string.
CATCH cx_sy_matcher .
BREAK-POINT.
EXIT.
ENDTRY.
gt_match_result2 = gx_matcher->find_all( ).
BREAK-POINT.
Looks like the class doesn't consider the start of line symbol (^). Is there an error in my implementation?
Any help is appreciated.
Matthias
2008 Apr 04 9:00 PM
Hi!
Not sure, but the documentation of hat (^) in ABAP's Find command says "Negation of a value set for single characters" (FIND->FIND - pattern ->Syntax of Regular Expressions ->Special Characters in Regular Expressions).
Best!
Jim
2008 Apr 07 12:11 PM
Hi Jim,
thank you for your reply. But to negate a value set of single characters you have to use
[^ ]
I used just the character
^
This is defined as anchor character for the start of a line (See the documentation link you posted -> chapter 'Special characters for search strings') .
As I understand it, should the FIND REGEX statement does the same as the CL_ABAP_REGEX and CL_ABAP_MATCHER classes. Therefore, I do not understand, why both implementations deliver another result.
And I didn't find an answer for that. Does anyone else?
Matthias
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |