.\" -*- coding: UTF-8 -*- .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Wed Jun 14 16:10:28 BST 1995 Wilf. (G.Wilford@ee.surrey.ac.uk) .\" Tiny change in formatting - aeb, 950812 .\" Modified 8 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk) .\" .\" show the synopsis section nicely .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH REGEX 3 "13 août 2020" GNU "Manuel du programmeur Linux" .SH NOM regcomp, regexec, regerror, regfree \- Fonctions POSIX pour les expressions rationnelles («\ regex\ ») .SH SYNOPSIS .nf \fB#include \fP .PP \fBint regcomp(regex_t *\fP\fIpreg\fP\fB, const char *\fP\fIregex\fP\fB, int \fP\fIcflags\fP\fB);\fP .PP \fBint regexec(const regex_t *\fP\fIpreg\fP\fB, const char *\fP\fIstring\fP\fB, size_t \fP\fInmatch\fP\fB,\fP \fB regmatch_t \fP\fIpmatch[]\fP\fB, int \fP\fIeflags\fP\fB);\fP .PP \fBsize_t regerror(int \fP\fIerrcode\fP\fB, const regex_t *\fP\fIpreg\fP\fB, char *\fP\fIerrbuf\fP\fB,\fP \fB size_t \fP\fIerrbuf_size\fP\fB);\fP .PP \fBvoid regfree(regex_t *\fP\fIpreg\fP\fB);\fP .fi .SH DESCRIPTION .SS "Compilation d'expressions rationnelles POSIX" \fBregcomp\fP() est utilisée pour compiler une expression rationnelle sous une forme utilisable par la suite pour des recherches avec \fBregexec\fP(). .PP On fournit à \fBregcomp\fP() les arguments \fIpreg\fP, un pointeur vers une zone de stockage du motif, \fIregex\fP, un pointeur vers une chaîne terminée par un caractère nul, et \fIcflags\fP, les attributs indiquant le type de compilation. .PP Toutes les recherches d'expressions rationnelles sont effectuées à travers la zone de motif compilé, ainsi \fBregexec\fP() doit toujours recevoir l'adresse d'un motif initialisé par \fBregcomp\fP(). .PP \fIcflags\fP is the bitwise\-\fBor\fP of zero or more of the following: .TP \fBREG_EXTENDED\fP Utiliser la syntaxe d'expression rationnelle étendue \fBPOSIX\fP pour interpréter \fIregex\fP. Sinon, la syntaxe d'expression rationnelle de base \fBPOSIX\fP est utilisée. .TP \fBREG_ICASE\fP Ne pas différencier les majuscules des minuscules. Les recherches \fBregexec\fP() suivantes utilisant le tampon de motif n'effectueront pas la différenciation. .TP \fBREG_NOSUB\fP Ne pas signaler la position des correspondances de chaînes. Les paramètres \fInmatch\fP et \fIpmatch\fP de \fBregexec\fP() ne sont pas pris en compte si le tampon de motif est compilé avec cet attribut. .TP \fBREG_NEWLINE\fP L'opérateur «\\ n'importe\-quel\-caractère\\ » ne s'identifie pas avec le saut de ligne. .IP A nonmatching list (\fB[\(ha...]\fP) not containing a newline does not match a newline. .IP Match\-beginning\-of\-line operator (\fB\(ha\fP) matches the empty string immediately after a newline, regardless of whether \fIeflags\fP, the execution flags of \fBregexec\fP(), contains \fBREG_NOTBOL\fP. .IP L'opérateur «\\ fin\-de\-ligne\\ » (\fB$\fP) s'identifie avec une chaîne vide précédant immédiatement un saut de ligne, même si l'attribut \fIeflags\fP contient \fBREG_NOTEOL\fP. .SS "Correspondance d'expressions rationnelles POSIX" \fBregexec\fP() is used to match a null\-terminated string against the precompiled pattern buffer, \fIpreg\fP. \fInmatch\fP and \fIpmatch\fP are used to provide information regarding the location of any matches. \fIeflags\fP is the bitwise\-\fBor\fP of zero or more of the following flags: .TP \fBREG_NOTBOL\fP L'opérateur «\\ début\-de\-ligne\\ » échoue toujours (mais voyez l'attribut de compilation \fBREG_NEWLINE\fP ci\-dessus). Cet attribut peut être utilisé quand différentes portions d'une chaîne sont transmises à \fBregexec\fP() et que le début de la chaîne ne correspond pas à un début de ligne. .TP \fBREG_NOTEOL\fP L'opérateur «\\ fin\-de\-ligne\\ » échoue toujours (mais voyez l'attribut de compilation \fBREG_NEWLINE\fP ci\-dessus). .TP \fBREG_STARTEND\fP Use \fIpmatch[0]\fP on the input string, starting at byte \fIpmatch[0].rm_so\fP and ending before byte \fIpmatch[0].rm_eo\fP. This allows matching embedded NUL bytes and avoids a \fBstrlen\fP(3) on large strings. It does not use \fInmatch\fP on input, and does not change \fBREG_NOTBOL\fP or \fBREG_NEWLINE\fP processing. This flag is a BSD extension, not present in POSIX. .SS "Décalage d'octets" À moins que l'attribut \fBREG_NOSUB\fP n'ait été utilisé lors de la compilation du motif, il est possible d'obtenir des informations sur les correspondances de chaînes. \fIpmatch\fP doit être dimensionnée pour contenir au moins \fInmatch\fP éléments. Ils sont remplis par \fBregexec\fP() avec les adresses des sous\-chaînes mises en correspondance. Les positions de la sous\-expression débutant à la \fIi\fPe parenthèse sont stockées dans \fIpmatch[i]\fP. Les adresses de mise en correspondance de l'expression complète sont stockées dans \fIpmatch[0]\fP. (Remarquez que pour obtenir les positions de correspondance de la sous\-expression \fIN\fP, \fInmatch\fP doit valoir au moins \fIN+1\fP.) Tous les éléments de structure inutilisés contiendront la valeur \-1. .PP La structure \fIregmatch_t\fP du type \fIpmatch\fP est définie dans \fI\fP. .PP .in +4n .EX typedef struct { regoff_t rm_so; regoff_t rm_eo; } regmatch_t; .EE .in .PP Chaque élément \fIrm_so\fP différent de \-1 indique le point de départ de la sous\-chaîne suivante la plus longue qui soit mise en correspondance. L'élément \fIrm_eo\fP indique le décalage de la fin de la sous\-chaîne, qui est l'emplacement du premier caractère après le texte qui correspond. .SS "Retours d'erreurs POSIX" \fBregerror\fP() est utilisé pour transformer les codes d'erreur renvoyés par \fBregcomp\fP() et par \fBregexec\fP() en libellés. .PP \fBregerror\fP() reçoit le code \fIerrcode\fP, le tampon de motif \fIpreg\fP, un pointeur sur une chaîne de caractères \fIerrbuf\fP, et la longueur maximale de cette chaîne \fIerrbuf_size\fP. Cette fonction renvoie la taille \fIerrbuf\fP nécessaire pour contenir le libellé d'erreur terminé par un caractère nul. Si \fIerrbuf\fP et \fIerrbuf_size\fP son non nuls, \fIerrbuf\fP est rempli avec les \fIerrbuf_size \- 1\fP premiers caractères du libellé d'erreur, suivis d'un caractère nul de terminaison («\ \e0\ »). .SS "Libération des tampons de motifs POSIX" En fournissant à \fBregfree\fP() un tampon de motif précompilé \fIpreg\fP, il libérera la mémoire allouée au tampon durant la compilation avec \fBregcomp\fP(). .SH "VALEUR RENVOYÉE" \fBregcomp\fP() renvoie zéro si la compilation réussit, ou un code d'erreur en cas d'échec. .PP \fBregexec\fP() renvoie zéro si la correspondance réussit, et \fBREG_NOMATCH\fP si elle échoue. .SH ERREURS Les erreurs suivantes peuvent être déclenchées par \fBregcomp\fP()\ : .TP \fBREG_BADBR\fP Utilisation illégale de l'opérateur de référence inverse. .TP \fBREG_BADPAT\fP Utilisation illégale d'un opérateur du type groupe ou liste. .TP \fBREG_BADRPT\fP Utilisation invalide d'opérateurs de répétition, comme un caractère «\ *\ » en première place. .TP \fBREG_EBRACE\fP Accolade manquante. .TP \fBREG_EBRACK\fP Crochet manquant. .TP \fBREG_ECOLLATE\fP Élément de classement invalide. .TP \fBREG_ECTYPE\fP Nom de classe de caractère inconnu. .TP \fBREG_EEND\fP Erreur non spécifique. Elle n'est pas définie par POSIX.2. .TP \fBREG_EESCAPE\fP Barre oblique inverse de fin. .TP \fBREG_EPAREN\fP Parenthèse manquante. .TP \fBREG_ERANGE\fP Utilisation illégale de l'opérateur d'intervalle. Par exemple, la fin de l'intervalle est inférieure au début de l'intervalle. .TP \fBREG_ESIZE\fP Compiled regular expression requires a pattern buffer larger than 64\ kB. This is not defined by POSIX.2. .TP \fBREG_ESPACE\fP Les routines regex ont épuisé la mémoire. .TP \fBREG_ESUBREG\fP Référence inverse illégale vers une sous\-expression. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbw20 lb lb l l l. Interface Attribut Valeur T{ \fBregcomp\fP(), \fBregexec\fP() T} Sécurité des threads MT\-Safe locale T{ \fBregerror\fP() T} Sécurité des threads MT\-Safe env T{ \fBregfree\fP() T} Sécurité des threads MT\-Safe .TE .SH CONFORMITÉ POSIX.1\-2001, POSIX.1\-2008. .SH EXEMPLES .EX #include #include #include #include #define ARRAY_SIZE(arr) (sizeof((arr)) / sizeof((arr)[0])) static const char *const str = "1) John Driverhacker;\en2) John Doe;\en3) John Foo;\en"; static const char *const re = "John.*o"; int main(void) { static const char *s = str; regex_t regex; regmatch_t pmatch[1]; regoff_t off, len; if (regcomp(®ex, re, REG_NEWLINE)) exit(EXIT_FAILURE); printf("String = \e"%s\e"\en", str); printf("Matches:\en"); for (int i = 0; ; i++) { if (regexec(®ex, s, ARRAY_SIZE(pmatch), pmatch, 0)) break; off = pmatch[0].rm_so + (s \- str); len = pmatch[0].rm_eo \- pmatch[0].rm_so; printf("#%d:\en", i); printf("offset = %jd; length = %jd\en", (intmax_t) off, (intmax_t) len); printf("substring = \e"%.*s\e"\en", len, s + pmatch[0].rm_so); s += pmatch[0].rm_eo; } exit(EXIT_SUCCESS); } .EE .SH "VOIR AUSSI" \fBgrep\fP(1), \fBregex\fP(7) .PP The glibc manual section, \fIRegular Expressions\fP .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Frédéric Hantrais . Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .