Professional Documents
Culture Documents
Regular Expressions For Information Processing in Abap: Ralph Benzinger Sap Ag
Regular Expressions For Information Processing in Abap: Ralph Benzinger Sap Ag
Information Processing
in ABAP
Ralph Benzinger
SAP AG
Regular Expression Primer
METHODS check
IMPORTING cardno TYPE c
RETURNING result TYPE abap_bool.
"…
METHODS retrieve
IMPORTING url TYPE c
RETURNING doc TYPE xstring.
"…
http://sap.com/&user=ralph&id=1234&lang=EN
Normalizing values:
Eliminate non-digits in phone number for data export
METHODS export
IMPORTING phoneno TYPE c
RETURNING digits TYPE n.
"…
496227747474
. * + ? | ^ $ ( ) [ ] { } \
DEMO_REGEX_TOY
cat
hat
sat
Cat
mat
text+off(len)
Use " RESULTS itab " addition when searching for all matches
Using CREATE
cl_abap_matcher interface
Finding
find_next( ) find_all( )
match( )
Replacing
replace_next( new )
Querying
get_line( )
(\d+) / (\d+)
… i r e d b y 1 0 / 3 1 a t t h e
1st submatch 2nd submatch
match_result-submatches
offset TYPE i
length TYPE i
((a+b)|(ba+))+
2/30/2006
^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30
|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2
-9]\d)?(?:0[48]|[2468][048]|[13579][26])|
(?:(?:16|[2468][048]|[3579][26])00)))(?:\
x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:
1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(
?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:
[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])
(:[0-5]\d){1,2})?$
Resources
recom-
NetWeaver ABAP Online Documentation mended
Two-article series on regular expressions to be published
in SAP Professional Journal
Books
Jeffrey Friedl: Mastering Regular Expressions,
O'Reilly
John Hopcroft and Jeffrey Ullman: Introduction to Automata Theory,
Languages, and Computation, Addison Wesley
Q&A