REGEX Function

Contingut

# REGEX

Troba i extreu, o opcionalment reemplaça, text, fent servir expressions regulars.

### Sintaxi

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

Text: A text or reference to a cell where the regular expression is to be applied.

Expression: A text representing the regular expression, using ICU regular expressions. If there is no match and Replacement is not given, #N/A is returned.

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.

### Exemples

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

=REGEX("123456ABCDEF";"[:digit:]";"Z";"g") retorna «ZZZZZZABCDEF», on tots els dígits es van reemplaçar per «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".

#### Informació tècnica

Aquesta funció és disponible des de la versió 6.2 del LibreOffice.

This function is NOT part of the Open Document Format for Office Applications (OpenDocument) Version 1.3. Part 4: Recalculated Formula (OpenFormula) Format standard. The name space is

ORG.LIBREOFFICE.REGEX

Temes relacionats

REGEX wiki page.

Llista d'expressions regulars

Expressions regulars de l'ICU (en anglès)

Funcions de text

Ens cal la vostra ajuda!