08-29-2007 7:02 PM
Hello all,
I'm a long time unix geek who's trying to make sense of regular expressions in ABAP. Look at this little program. If I run it as shown, it's successful.
If I use "Gzzxx" , it's not.
Can anyone explain this. That would be a perfectly valid string in any other tool I've used that supports regular expressions, whether that be a unix shell, perl, awk, or ruby.
REPORT zebj_hack5.
PARAMETERS:
p_input TYPE string DEFAULT 'xxxxGGGGzzzzxxxxGGGGzzzz' LOWER CASE,
p_regex TYPE string DEFAULT 'Gz' LOWER CASE,
p_all as checkbox.
START-OF-SELECTION.
FIND FIRST OCCURRENCE OF p_regex IN p_input.
IF sy-subrc = 0 .
WRITE:/ p_regex, ' found in ', p_input.
ELSE.
WRITE:/ p_regex , ' not found'.
ENDIF.
08-29-2007 7:16 PM
do it this way
IF p_input cp p_regex..
WRITE:/ p_regex, ' found in ', p_input.
ELSE.
WRITE:/ p_regex , ' not found'.
ENDIF.
08-29-2007 7:33 PM
Thanks for your reply Mahesh. But, that's not an example of regular expression matching. That's the older "contains pattern" technique.
Example:
regular expression "G.zx.G"
would match the p_input string from the first G to the last G
08-29-2007 7:24 PM
Well RegEx is a little differnt in ABAP than what you are showing there. See this doc.
and
http://help.sap.com/saphelp_nw70/helpdata/en/42/9d6ceabb211d73e10000000a1553f6/frameset.htm
Regards,
RIch Heilman
08-29-2007 7:36 PM
Thanks, Rich.
I've tried the latter link from the help.sap.com, but it's quite confusing.
I guess I'll just try harder.
BTW. I bought your new book. Very nice.
08-29-2007 7:44 PM
Thanks for your support Ed. Hope it is helping. RegEx is not specific to ABAP, it is widely used in other languages, but just recently brought to the ABAP stack, so there's not much out there in that regard, and yes I found it very confusing too.
http://en.wikipedia.org/wiki/Regular_expression
Regards,
Rich Heilman