‎2013 Jan 31 4:22 PM
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:'.
WRITE: lv_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
‎2013 Feb 01 6:04 PM
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