ABAP regular expression

Time:2021-5-5

Regular expression is more complex, but you can use regular expression to kill many programmers, because others have written a lot of bad code, you can do it in one sentence.

se24 CL_ABAP_MATCHER

Exercise 1:
^[0-9]+abc$
^Enter the starting position of the string for the match.

[0-9] + matches multiple numbers, [0-9] matches a single number, + matches one or more.

ABC $matches the letter ABC and ends with ABC, and $is the end position of the matching input string.

The above regular expression translates as ^ starting to search for any number from 0 to 9 and ending with an ABC.

Test with ABAP language

DATA: matcher TYPE REF TO cl_abap_matcher,
      match   TYPE match_result,
      itab    TYPE match_result_tab,
      line    LIKE LINE OF itab.
matcher = cl_abap_matcher=>create( pattern = '^[0-9]+abc$' text = '123abc' ).
itab = matcher->find_all( ).
LOOP AT itab INTO line.
  WRITE: / matcher->text,line-offset,line-length,matcher->text+line-offset(line-length).
ENDLOOP.

Results of operation:
123abc 0 6 123abc

Recommended Today

Analysis of super comprehensive MySQL statement locking (Part 1)

A series of articles: Analysis of super comprehensive MySQL statement locking (Part 1) Analysis of super comprehensive MySQL statement locking (Part 2) Analysis of super comprehensive MySQL statement locking (Part 2) Preparation in advance Build a system to store heroes of the Three KingdomsheroTable: CREATE TABLE hero ( number INT, name VARCHAR(100), country varchar(100), PRIMARY […]