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

Libp2p RS version 0.3.0 introduction

V0.3.0 released on 4.23, usingAsyncRead & AsyncWriteTo replace ourReadEx & WriteEx & SplitEx; SimplifiedKad/DHTImplementation logic. modify ReadEx & WriteEx & SplitEx: At first we tried to useasync-traitTo define their own IO operationsTraitFor more pure useasync/awaitTo write code. withReadExFor example, it is roughly as follows: #[async_trait] pub trait ReadEx { async fn read(&mut self, buf: &mut […]