Documentazione/Funzioni di Calc/ESPR.REG

    From The Document Foundation Wiki
    This page is a translated version of the page Documentation/Calc Functions/REGEX and the translation is 17% complete.
    Other languages:


    Nome funzione:

    ESPR.REG

    Categoria:

    Testo

    Riepilogo:

    Confronta una stringa di testo con un'espressione regolare ed estrae o sostituisce il testo corrispondente, a seconda delle impostazioni dell'argomento.

    Sintassi:

    ESPR.REG(Testo; Espressione[; [Sostituzione][; Spunte o occorrenza]])

    Restituisce:

    Restituisce uno dei seguenti a seconda dei valori degli argomenti. Per ulteriori informazioni sulla occorrenza di ciascun tipo restituito (con esempi), vedere la sezione #Additional details: di seguito.

    1. Una copia di una sottostringa estratta dal testo originale.
    2. Una copia del testo originale, modificata sostituendo una o più corrispondenze.
    3. A copy of the original text, unmodified.
    4. A value not available error (#N/D).

    Argomenti:

    Text is a text string (in quotation marks), or a reference to a cell containing a text string, that is the original text to which Expression is to be applied.

    Expression is a text string (in quotation marks), or a reference to a cell containing a text string, that is the regular expression to be applied to Text.

    Replacement is a text string (in quotation marks), or a reference to a cell containing a text string, that is the replacement text to be used. Setting Replacement to the empty string can be used as a mechanism to delete matched characters.

    Flags or Occurrence is one of the following options:

    1. A string comprising a single lowercase "g" character, or a reference to a cell containing such a text string. The "g" character is used to select global replacement, so that any replacement is applied to all matches.
    2. A non-negative integer, or a reference to a cell containing such an integer, that indicates which specific match is to be used.
    • If Expression is not a valid regular expression, then ESPR.REG reports an invalid argument error (Err:502).
    • If Flags or Occurrence is a non-numeric text string that contains any character other than a single lowercase "g", then ESPR.REG reports an invalid argument error (Err:502).
    • If Flags or Occurrence is a negative numeric value, then ESPR.REG reports an invalid argument error (Err:502).
    • If Flags or Occurrence is a non-negative, non-integer numeric value, then ESPR.REG uses its floor value.
    • If Replacement is omitted and Flags or Occurrence is set to "g", then ESPR.REG behaves as if both Replacement and Flags or Occurrence were omitted.

    Dettagli aggiuntivi:

    Details specific to ESPR.REG function

    • Operation of the ESPR.REG function is not dependent on the option that is currently selected in the Formulas Wildcards area of the Tools ▸ Options ▸ LibreOffice Calc ▸ Calculate (or LibreOffice ▸ Preferences ▸ LibreOffice Calc ▸ Calculate on macOS) dialog.
    • The initial default is for ESPR.REG to use case-sensitive matching but this can be changed using flags inside the ICU regular expression. For example, include "(?i)" within the regular expression to change to a case-insensitive match, like in =ESPR.REG("test","(?i)"& "TEST").
    • The original string passed in the Text argument is not affected by any replacements made by ESPR.REG – changes are reflected only in the returned string.
    • It may be helpful to consider ESPR.REG as operating in one of five distinct "modes" depending on the arguments passed to the function. These modes are as follows:
    1. ESPR.REG(Text; Expression) extracts the first match of Expression in Text. This simple form can be useful for checking that a string conforms to some predefined pattern (such as, telephone numbers, email addresses, zip codes, etc).
      • The formula =ESPR.REG("LibreOffice Calc"; ".c") extracts the first occurrence of a lowercase "c" preceded by any other character and returns the string "ic".
      • The formula =ESPR.REG("LibreOffice Calc"; "Z") finds no match and returns #N/D.
    2. ESPR.REG(Text; Expression; Replacement) replaces the first match of Expression in Text with Replacement. If there is a match, ESPR.REG returns the modified version of Text; if there is no match, Text is returned unmodified.
      • The formula =ESPR.REG("Initialise new variables and optimise your code."; "ise"; "ize") returns "Initialize new variables and optimise your code.".
      • The formula =ESPR.REG("LibreOffice Calc"; "Z"; "?") finds no match and returns the string "LibreOffice Calc" unmodified.
    3. ESPR.REG(Text; Expression; Replacement; "g") replaces all matches of Expression in Text with Replacement. If there is a match, ESPR.REG returns the modified version of Text; if there is no match, Text is returned unmodified.
      • The formula =ESPR.REG("Initialise new variables and optimise your code."; "ise"; "ize"; "g") returns "Initialize new variables and optimize your code.".
      • The formula =ESPR.REG("LibreOffice Calc"; "Z"; "?"; "g") finds no match and returns the string "LibreOffice Calc" unmodified.
    4. ESPR.REG(Text; Expression; ; Occurrence) extracts the nth match of Expression in Text (where n is given by the value of the Occurrence argument).
      • The formula =ESPR.REG("LibreOffice Calc"; ".c"; ; 1) extracts the first occurrence of a lowercase "c" preceded by any other character and returns the string "ic".
      • The formula =ESPR.REG("LibreOffice Calc"; ".c"; ; 2) extracts the second occurrence of a lowercase "c" preceded by any other character and returns the string "lc".
      • The formula =ESPR.REG("LibreOffice Calc"; ".c"; ; 3) finds no match and returns #N/D.
      • The value of 0 for Occurrence is a special case, for which ESPR.REG returns Text unmodified.
    5. ESPR.REG(Text; Expression; Replacement; Occurrence) replaces the nth match of Expression in Text with Replacement (where n is given by the value of the Occurrence argument). If there is a match, ESPR.REG returns the modified version of Text; if there is no match, Text is returned unmodified.
      • The formula =ESPR.REG("Initialise new variables and optimise your code."; "ise"; "ize"; 1) returns "Initialize new variables and optimise your code.".
      • The formula =ESPR.REG("Initialise new variables and optimise your code."; "ise"; "ize"; 2) returns "Initialise new variables and optimize your code.".
      • The formula =ESPR.REG("Initialise new variables and optimise your code."; "ise"; "ize"; 3) returns the string "Initialise new variables and optimise your code." unmodified.
      • The value of 0 for Occurrence is a special case, for which ESPR.REG returns Text unmodified.


    Informazioni generali sulle espressioni regolari in Calc

    Note pin.svg

    Nota:
    Per comodità, le informazioni di questa sezione sono ripetute su tutte le pagine che descrivono le funzioni che gestiscono le espressioni regolari.

    • Un'espressione regolare è una stringa di caratteri che definisce una sequenza di testo da ricercare. Potete trovare maggiori e più dettagliate informazioni sulla pagina di Wikipedia relativa alle Espressioni regolari.
    • Le espressioni regolari sono ampiamente usate in molti campi e sono disponibili molteplici processori di espressioni regolari. Calc utilizza il pacchetto open source Regular Expressions della International Components for Unicode (ICU). Vedere la loro documentazione sulle Espressioni regolari per maggiori dettagli, che comprendono la definizione integrale della sintassi delle Espressioni regolari ICU.
    • In aggiunta a ciò, la guida in linea di LibreOffice fornisce un elenco delle espressioni regolari di alto livello.
    • Il motore per le espressioni regolari di Calc supporta il rilevamento di gruppi numerati, che consentono di identificare dei sotto intervalli all'interno di una corrispondenza e di usarli all'interno di un testo sostitutivo. Le parentesi sono usate per raggruppare i componenti di un'espressione regolare e creare un gruppo numerato. Per inserire un gruppo rilevato all'interno di un testo sostitutivo, usate il formato "$n", nel quale n è il numero del gruppo rilevato.

    Esempi:

    Formula Descrizione Restituisce
    =ESPR.REG("123456ABCDEF"; "[:digit:]"; "Z") Here the function returns "Z23456ABCDEF", where the first match of a digit is replaced by "Z". Z23456ABCDEF
    =ESPR.REG(D1; D2; D3; D4) where cells D1 to D4 contain the strings "123456ABCDEF", "[:digit:]", "Z", and "g" respectively. Here the function returns "ZZZZZZABCDEF", where all digits are replaced by "Z". ZZZZZZABCDEF
    =ESPR.REG("123456ABCDEF"; "[126]"; ""; "g") Here the function returns "345ABCDEF", where any occurrence of "1", "2", or "6" is replaced by the empty string, and thus deleted. 345ABCDEF
    =ESPR.REG("axbxcxd"; ".x"; ; 2) Here the function returns "bx", the second match of ".x". bx
    =ESPR.REG("axbxcxd"; "(.)x"; "$1y"; 2) Here the function returns "axbycxd", the second match of "(.)x" (i.e. "bx") is replaced with the captured group of one character (i.e. "b") followed by "y". axbycxd
    =ESPR.REG("LibreOffice Calc"; "libreoffice") Here the function returns #N/D because by default matching is case-sensitive. #N/D
    =ESPR.REG("LibreOffice Calc"; "(?i)libreoffice") Here the function finds a match and returns "LibreOffice", because the (?i) search flag switches to a case-insensitive match. LibreOffice

    Funzioni di LibreOffice correlate:

    Nessuno.

    Standard ODF:

    Nessuno

    Funzioni equivalenti (o simili) di Excel:

    Nessuno