Contenido
Índice 🔎︎

# EXP.REG

Encuentra y extrae, u opcionalmente reemplaza, texto, con ayuda de expresiones regulares.

Esta función está disponible desde la versión 6.2 de LibreOffice.

#### Sintaxis

REGEX( Text ; Expression [ ; [ Replacement ] [ ; Flags|Occurrence ] ] )

Texto: un texto o una referencia a una celda en la que deberá aplicarse la expresión regular.

Expresión: un texto que representa la expresión regular, utilizando la sintaxis de ICU. Si no se produce ningún resultado y no se proporciona Reemplazo, se devuelve #N/D.

Replacement: Optional. The replacement text and references to capture groups. If there is no match, Text is returned unmodified.

Flags: Optional. "g" replaces all matches of Expression in Text, not extracted. If there is no match, Text is returned unmodified.

Occurrence: Optional. Number to indicate which match of Expression in Text is to be extracted or replaced. If there is no match and Replacement is not given, #N/A is returned. If there is no match and Replacement is given, Text is returned unmodified. If Occurrence is 0, Text is returned unmodified.

#### Ejemplos

=REGEX("123456ABCDEF";"[:digit:]";"Z") returns "Z23456ABCDEF", where the first match of a digit is replaced by "Z".

=REGEX("123456ABCDEF";"[:digit:]";"Z";"g") returns "ZZZZZZABCDEF", where all digits were replaced by "Z".

=REGEX("123456ABCDEF";"[126]";"";"g") returns "345ABCDEF", where any occurrence of "1", "2" or "6" is replaced by the empty string, thus deleted.

=REGEX("axbxcxd";".x";;2) returns "bx", the second match of ".x".

=REGEX("axbxcxd";"(.)x";"$1y";2) returns "axbycxd", the second match of "(.)x" (i.e. "bx") replaced with the captured group of one character (i.e. "b") followed by "y".

Temas relacionados

Lista de expresiones regulares

Expresiones regulares de ICU (recurso en inglés)