.\" -*- 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 Agosto 2020" GNU "Manual del Programador de Linux" .SH NOMBRE regcomp, regexec, regerror, regfree \- funciones para expresiones regulares POSIX .SH SINOPSIS .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 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 Una lista de no\-coincidencia (\fB[\(ha...]\fP) que no contenga un carácter "nueva línea" no coincidirá con una "nueva línea". .IP Un operador "coincidir al principio de línea" (\fB\(ha\fP) coincide con la cadena vacía inmediatamente posterior a un carácter "nueva línea", sin tener en cuenta si \fIeflags\fP, la bandera de ejecución de \fBregexec\fP(), contiene \fBREG_NOTBOL\fP o no. .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" Si a \fBregfree\fP() se le pasa un buffer de patrones precompilados, \fIpreg\fP, liberará la memoria del buffer de patrones reservada por el proceso de compilación, \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 Uso incorrecto de operadores de repetición, como el uso de \(aq*\(aq como primer carácter. .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). .TS allbox; lbw20 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 .SH "CONFORME A" 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 (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 "VÉASE TAMBIÉN" \fBgrep\fP(1), \fBregex\fP(7) .PP The glibc manual section, \fIRegular Expressions\fP .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Juan Piernas . 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. 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 .