Regular expressions are complicated, but they kill a lot of programmers because other people write a lot of bad code and you can do it in a single sentence.


Exercise 1: ^[0-9]+ ABC $^ matches the starting position of the input string.

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

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

The above regular expression translates to ^ starting the search for any number from 0 to 9, and adding an “ABC” ending.

Use ABAP language to test

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).

Result: 123abc 0 6 123abc