Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regular expression confusion

Former Member
0 Likes
708

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.

5 REPLIES 5
Read only

Former Member
0 Likes
663

do it this way

IF p_input cp p_regex..

WRITE:/ p_regex, ' found in ', p_input.

ELSE.

WRITE:/ p_regex , ' not found'.

ENDIF.

Read only

0 Likes
663

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
Read only

0 Likes
663

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.

Read only

0 Likes
663

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