User Tools

Site Tools


abap:regex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
abap:regex [2017/01/03 17:16] – created ginkoabap:regex [2021/07/23 18:23] (current) ginko
Line 1: Line 1:
 ====== Regex ====== ====== Regex ======
 +===== Caractères spéciaux =====
 +Les ancres de fin de ligne (''$'') fonctionnent en accord avec le [[http://ginkobox.fr/work/wiki/doku.php?id=abap:chars|fonctionnement des chaines de caractères dans SAP]] : en cas de chaine de longueur fixe, un pattern ne matchera que si on prend en compte les trailing blanks (par exemple en terminant le pattern par ' *$' plutôt que seulement '$'):
 +<code abap>DATA f(6).
 +f = 'T01'.
 +IF find( val = f = '^T\d{2} *$' ) >= 0.
 +  " Your process
 +ENDIF.</code>
 +===== Fonction prédéfinie =====
 +La fonction ''find'' renvoie la position du match en ''integer'' :
 +  * -1 si pas de match
 +  * 0 si début de la chaine
 +  * 1, n sinon
 +
 +===== cl_abap_matcher =====
 +
 +**IMPORTANT** : Pour utiliser le matcher, il faut que la regex couvre tout le texte (genre commencer et finir par ''.*'' si les subgroups intéressants ne couvrent pas tout le texte) !
 +
 +[[https://codezentrale.de/tag/cl_abap_matcher/|Sauce]]
 +
 +<code abap>DATA(matcher) = cl_abap_matcher=>create( pattern     = '^/category/([0-9]{1,5})/item/([0-9]{1,2})$'
 +                                         text        = '/category/12345/item/12'
 +                                         ignore_case = abap_true ).
 + 
 +IF abap_true = matcher->match( ).
 +* erstes Match
 +  WRITE: / matcher->get_submatch( 1 ).
 +* zweites Match
 +  WRITE: / matcher->get_submatch( 2 ).
 +ENDIF.</code>
  
abap/regex.1483460213.txt.gz · Last modified: 2017/01/03 17:16 by ginko