Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
prog:lazarus:classes:tregexpr [08/03/2021 18:46] thierry [Sources & Ressources] |
prog:lazarus:classes:tregexpr [09/03/2021 15:46] (Version actuelle) thierry [Exemple d'utilisation] |
||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== TRegExpr ====== | ====== TRegExpr ====== | ||
| + | ===== Exemple d'utilisation ===== | ||
| + | <code delphi [enable_line_numbers="true"]> | ||
| + | procedure TMainForm.RegExecute(ARegex, AText: string); | ||
| + | var | ||
| + | vReg: TRegExpr; | ||
| + | vI: integer; | ||
| + | |||
| + | begin | ||
| + | MMRes.Clear; | ||
| + | vReg := TRegExpr.Create(ARegex); | ||
| + | try | ||
| + | if vReg.Exec(AText) then | ||
| + | begin | ||
| + | repeat | ||
| + | MMRes.Lines.add('RegExpr.SubExprMatchCount=%d', [vReg.SubExprMatchCount]); | ||
| + | if vReg.SubExprMatchCount > 0 then | ||
| + | begin | ||
| + | for vI := 0 to vReg.SubExprMatchCount do | ||
| + | begin | ||
| + | MMRes.Lines.add(''); // ligne vide | ||
| + | MMRes.Lines.add('RegExpr.Match[%d]=''%s''', [vI, vReg.Match[vI]]); | ||
| + | MMRes.Lines.add('RegExpr.MatchPos[%d]=%d', [vI, vReg.MatchPos[vI]]); | ||
| + | MMRes.Lines.add('RegExpr.MatchLen[%d]=%d', [vI, vReg.MatchLen[vI]]); | ||
| + | end; | ||
| + | end; | ||
| + | until not vReg.ExecNext; | ||
| + | end; | ||
| + | finally | ||
| + | vReg.Free; | ||
| + | end; | ||
| + | end; | ||
| + | |||
| + | </code> | ||
| + | |||
| ===== Sources & Ressources ===== | ===== Sources & Ressources ===== | ||
| * [[https://rchastain.developpez.com/tutoriel/pascal/expressions-regulieres/|Expressions régulières avec l'unité RegExpr de Free Pascal @ Developpez.com]] | * [[https://rchastain.developpez.com/tutoriel/pascal/expressions-regulieres/|Expressions régulières avec l'unité RegExpr de Free Pascal @ Developpez.com]] | ||
| + | * [[https://regex101.com/|REGEX101.COM un testeur d'expressions régulières]] | ||