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

ABAP regex hex implementation

Former Member
0 Likes
865

hi!

for data validation, we use regex rules. But I have a question to the implementation in ABAP.

To validate a string is ASCII, regex allows to provide the full charset or just the hex-value from-to. But ABAP does not threat this as expected. See the code below.

DATA: lv_str TYPE string VALUE
       ' !"#$%&''''()*+,-./0-9:;<=>?@ABCDEFGHIJKLMNOPQRZTUVWXYZ0123456789[|]^_`a-z]{|}~',
       lv_regx_str TYPE string VALUE
       '[^\ \!\"\#\$\%\&\''''\(\)\*\+\,\-\.\/0-9\:\;\<\=\>\?\@\A-Z\\\[\|\]\^\_\`\a-z\]\{\|\}\~]',
       lv_regx_hex TYPE string VALUE
       '[^\x20-\x7F]',

       lv_str_str TYPE string,
       lv_str_hex TYPE string.

lv_str_str = lv_str.
lv_str_hex = lv_str.

REPLACE ALL OCCURRENCES OF REGEX lv_regx_str IN lv_str_str WITH '?'.
REPLACE ALL OCCURRENCES OF REGEX lv_regx_hex IN lv_str_hex WITH '?'.

IF lv_str_hex NE lv_str_str.
   WRITE: 'Hex:'.
   WRITE: lv_str_hex.
   WRITE /: 'Str:'.
   WRITElv_str_str.
ENDIF.

The output of this program is:

Hex:

?????????????????0?9:;<=>?@ABCDEFGHIJKLMNOPQRZTUVWXYZ0123456789[?]^_`a??]????

Str:

  !"#$%&''()*+,-./0-9:;<=>?@ABCDEFGHIJKLMNOPQRZTUVWXYZ0123456789[ ]^_`a-z]{ }~

So the hex regex works in general: there is no exception and standard characters A-Z and 0-9 are untouched. But chars like !$%& are not accepted.

Any ideas?

Thanks,

Roland

1 REPLY 1
Read only

former_member491621
Contributor
0 Likes
538

Hi Roland,

Please check the below link for reference. You might get your answer

http://help.sap.com/abapdocu_70/en/ABENREGEX_SYNTAX_SPECIALS.htm