.\" -*- coding: UTF-8 -*- '\" t .\" Copyright (C), 1995, Graeme W. Wilford. (Wilf.) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" 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 "5 Febrero 2023" "Páginas de manual de Linux 6.03" .SH NOMBRE regcomp, regexec, regerror, regfree \- funciones para expresiones regulares POSIX .SH BIBLIOTECA Biblioteca Estándar C (\fIlibc\fP, \fI\-lc\fP) .SH SINOPSIS .nf \fB#include \fP .PP \fBint regcomp(regex_t *restrict \fP\fIpreg\fP\fB, const char *restrict \fP\fIregex\fP\fB,\fP \fB int \fP\fIcflags\fP\fB);\fP \fBint regexec(const regex_t *restrict \fP\fIpreg\fP\fB, const char *restrict \fP\fIstring\fP\fB,\fP \fB size_t \fP\fInmatch\fP\fB, regmatch_t \fP\fIpmatch\fP\fB[restrict .\fP\fInmatch\fP\fB],\fP \fB int \fP\fIeflags\fP\fB);\fP .PP \fBsize_t regerror(int \fP\fIerrcode\fP\fB, const regex_t *restrict \fP\fIpreg\fP\fB,\fP \fB char \fP\fIerrbuf\fP\fB[restrict .\fP\fIerrbuf_size\fP\fB], size_t \fP\fIerrbuf_size\fP\fB);\fP \fBvoid regfree(regex_t *\fP\fIpreg\fP\fB);\fP .fi .SH DESCRIPCIÓN .SS "Compilación de expresiones regulares POSIX" \fBregcomp\fP() se utiliza para compilar una expresión regular en un formato apropiado para ser usado por \fBregexec\fP() en búsquedas posteriores. .PP A \fBregcomp\fP() se le pasan como parámetros \fIpreg\fP, un puntero a un área de almacenamiento temporal de patrones, \fIregex\fP, un puntero a una cadena terminada en un carácter nulo y \fIcflags\fP, banderas utilizadas para determinar el tipo de compilación. .PP Toda búsqueda con expresiones regulares se debe realizar mediante un buffer de patrones compilados, por tanto, a \fBregexec\fP() siempre se le debe proporcionar la dirección de un buffer de patrones inicializado mediante \fBregcomp\fP(). .PP \fIcflags\fP is the bitwise\-\fBor\fP of zero or more of the following: .TP \fBREG_EXTENDED\fP Utilizar el tipo de sintaxis 'Expresión Regular Extendida \fBPOSIX\fP' cuando se interprete \fIregex\fP. Si no se activa esta opción, se utiliza el tipo de sintaxis 'Expresión Regular Básica \fBPOSIX\fP'. .TP \fBREG_ICASE\fP No distinguir entre mayúsculas y minúsculas. Las siguientes búsquedas \fBregexec\fP() que usen este buffer de patrones no distinguirán entre mayúsculas y minúsculas. .TP \fBREG_NOSUB\fP Do not report position of matches. The \fInmatch\fP and \fIpmatch\fP arguments to \fBregexec\fP() are ignored if the pattern buffer supplied was compiled with this flag set. .TP \fBREG_NEWLINE\fP Los operadores "coincidir con cualquier carácter" no coinciden con un carácter "nueva línea". .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 Un operador "coincidir al final de línea" (\fB$\fP) coincide con la cadena vacía inmediatamente anterior a un carácter "nueva línea", sin tener en cuenta si \fIeflags\fP contiene \fBREG_NOTEOL\fP o no. .SS "Coincidencias en las expresiones regulares 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 El operador "coincidir al principio de línea" siempre falla en las coincidencias (pero vea la opción de compilación \fBREG_NEWLINE\fP más arriba). Esta bandera se puede utilizar cuando se pasan diferentes porciones de una cadena a \fBregexec\fP() y el comienzo de la cadena no se debe interpretar como el principio de una línea. .TP \fBREG_NOTEOL\fP El operador "coincidir al final de línea" siempre falla en la coincidencias (pero vea la opción de compilación \fBREG_NEWLINE\fP más arriba). .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 "Desplazamientos de bytes" Unless \fBREG_NOSUB\fP was set for the compilation of the pattern buffer, it is possible to obtain match addressing information. \fIpmatch\fP must be dimensioned to have at least \fInmatch\fP elements. These are filled in by \fBregexec\fP() with substring match addresses. The offsets of the subexpression starting at the \fIi\fPth open parenthesis are stored in \fIpmatch[i]\fP. The entire regular expression's match addresses are stored in \fIpmatch[0]\fP. (Note that to return the offsets of \fIN\fP subexpression matches, \fInmatch\fP must be at least \fIN+1\fP.) Any unused structure elements will contain the value \-1. .PP La estructura \fIregmatch_t\fP, que es el tipo de \fIpmatch\fP, se define en \fI\fP. .PP .in +4n .EX typedef struct { regoff_t rm_so; regoff_t rm_eo; } regmatch_t; .EE .in .PP Each \fIrm_so\fP element that is not \-1 indicates the start offset of the next largest substring match within the string. The relative \fIrm_eo\fP element indicates the end offset of the match, which is the offset of the first character after the matching text. .SS "Informes de error POSIX" \fBregerror\fP() se utiliza para convertir los códigos de error que pueden devolver tanto \fBregcomp\fP() como \fBregexec\fP() en cadenas de mensaje de error. .PP \fBregerror\fP() is passed the error code, \fIerrcode\fP, the pattern buffer, \fIpreg\fP, a pointer to a character string buffer, \fIerrbuf\fP, and the size of the string buffer, \fIerrbuf_size\fP. It returns the size of the \fIerrbuf\fP required to contain the null\-terminated error message string. If both \fIerrbuf\fP and \fIerrbuf_size\fP are nonzero, \fIerrbuf\fP is filled in with the first \fIerrbuf_size \- 1\fP characters of the error message and a terminating null byte (\[aq]\e0\[aq]). .SS "Liberación de buffers de patrones POSIX" Supplying \fBregfree\fP() with a precompiled pattern buffer, \fIpreg\fP, will free the memory allocated to the pattern buffer by the compiling process, \fBregcomp\fP(). .SH "VALOR DEVUELTO" \fBregcomp\fP() devuelve cero si la compilación tiene éxito y un código de error si falla. .PP \fBregexec\fP() devuelve cero si hay coincidencia y \fBREG_NOMATCH\fP en caso de fallo. .SH ERRORES \fBregcomp\fP() puede devolver los siguientes errores: .TP \fBREG_BADBR\fP Uso incorrecto del operador de referencia inversa. .TP \fBREG_BADPAT\fP Uso incorrecto de operadores de patrón tales como grupo o lista. .TP \fBREG_BADRPT\fP Invalid use of repetition operators such as using \[aq]*\[aq] as the first character. .TP \fBREG_EBRACE\fP Existe una llave de un operador de intervalo no emparejada. .TP \fBREG_EBRACK\fP Existe un corchete de un operador de lista no emparejado. .TP \fBREG_ECOLLATE\fP Elemento de comparación inválido. .TP \fBREG_ECTYPE\fP Nombre de clase de caracteres desconocido. .TP \fBREG_EEND\fP Error indefinido. No definido por POSIX.2. .TP \fBREG_EESCAPE\fP Barra invertida (\e) al final. .TP \fBREG_EPAREN\fP Existe un paréntesis de un operador de grupo no emparejado. .TP \fBREG_ERANGE\fP Uso incorrecto de un operador de rango; por ejemplo, el límite superior del rango ocurre antes que el límite inferior. .TP \fBREG_ESIZE\fP La expresión regular compilada necesita un buffer de patrones mayor que 64\ kB. No definido por POSIX.2. .TP \fBREG_ESPACE\fP Las rutinas de expresiones regulares se ejecutaron fuera de sus límites de memoria. .TP \fBREG_ESUBREG\fP Referencia inversa incorrecta a una subexpresión. .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .ad l .nh .TS allbox; lbx lb lb l l l. Interfaz Atributo Valor T{ \fBregcomp\fP(), \fBregexec\fP() T} Seguridad del hilo Configuración regional de multi\-hilo seguro T{ \fBregerror\fP() T} Seguridad del hilo MT\-Safe env T{ \fBregfree\fP() T} Seguridad del hilo Multi\-hilo seguro .TE .hy .ad .sp 1 .SH ESTÁNDARES POSIX.1\-2001, POSIX.1\-2008. .SH EJEMPLOS .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 (unsigned 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("#%zu:\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 "VÉASE TAMBIÉN" \fBgrep\fP(1), \fBregex\fP(7) .PP The glibc manual section, \fIRegular Expressions\fP .PP .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Juan Piernas . .PP Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. .PP Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org .ME .