Contingut

# Llista d'expressions regulars

Per a una llista completa dels metacaràcters i llur sintaxi, vegeu la documentació sobre les expressions regulars de l'ICU (en anglès).

Cells with the empty string ("") are not equivalent to blank cells. When searching or calculating with text, the empty string "" is the text with length zero.

Terme | Representació/ús
--- | ---
Qualsevol caràcter | The given character, unless it is a regular expression meta character. The list of meta characters follows in this table.
. | Any single character except a line break or a paragraph break. For example, the search term "sh.rt" matches both "shirt" and "short".
^ | The beginning of a paragraph or cell. Special objects such as empty fields or character-anchored frames, at the beginning of a paragraph are ignored. Example: "^Peter" matches the word "Peter" only when it is the first word of a paragraph.
$ | The end of a paragraph or cell. Special objects such as empty fields or character-anchored frames at the end of a paragraph are ignored. Example: "Peter$" matches only when the word "Peter" is the last word of a paragraph, note "Peter" cannot be followed by a period. $ per si mateix coincideix amb el fi de paràgraf. Així és possible cercar i substituir salts de paràgraf.
* | Zero or more of the regular expression term immediately preceding it. For example, "Ab*c" matches "Ac", "Abc", "Abbc", "Abbbc", and so on.
+ | One or more of the regular expression term immediately preceding it. For example, "AX.+4" finds "AXx4", but not "AX4". The longest possible string that matches this regular expression in a paragraph is always matched. If the paragraph contains the string "AX 4 AX4", the entire passage is highlighted.
? | Zero or one of the regular expression term immediately preceding it. For example, "Texts?" matches "Text" and "Texts" and "x(ab|c)?y" finds "xy", "xaby", or "xcy".
\ | The special character that follows it is interpreted as a normal character and not as a regular expression meta character (except for the combinations "\n", "\t", "\b", "\>" and "\<"). For example, "tree\." matches "tree.", not "treed" or "trees".
\n | When entered in the Find text box, finds a line break that was inserted with the Shift+Enter key combination in Writer, or the Ctrl+Enter key combination in a Calc cell. When entered in the Replace text box in Writer, inserts a paragraph break that can be inserted with the Enter or Return key. It has no special meaning in Calc, and is treated literally there. To change line breaks into paragraph breaks in Writer, enter \n in both the Find and Replace boxes, and then perform a search and replace.
\t | A tab character. Can also be used in the Replace box.
\b | A word boundary. For example, "\bbook" matches "bookmark" and "book" but not "checkbook" whereas "book\b" matches "checkbook" and "book" but not "bookmark". Note, this form replaces the obsolete (although they still work for now) forms "\>" (match end of word) and "\<" (match start of word).
\w | Match a word character.
\W | Match a non-word character.
^$ | Troba un paràgraf buit.
^. | Cerca el primer caràcter d'un paràgraf.
& o $0 | Adds the string that was found by the search criteria in the Find box to the term in the Replace box when you make a replacement. For example, if you enter "window" in the Find box and "&frame" in the Replace box, the word "window" is replaced with "windowframe". You can also enter an "&" in the Replace box to modify the Attributes or the Format of the string found by the search criteria.
[...] | Qualsevol aparició única de qualsevol dels caràcters que es troben entre claudàtors. Per exemple: «[abc123]» coincideix amb els caràcters «a», «b», «c», «1», «2» i «3». «[a-e]» coincideix amb aparicions úniques dels caràcters de la «a» a la «e», tots dos inclusivament (l'interval ha d'especificar-se amb el caràcter que tingui el número de codi Unicode més petit en primer lloc). «[a-eh-x]» coincideix amb qualsevol aparició única dels caràcters que es troben en els intervals de la «a» a la «e» i de la «h» a la «x».
[^...] | Any single occurrence of a character, including Tab, Space and Line Break characters, that is not in the list of characters specified inclusive ranges are permitted. For example "[^a-syz]" matches all characters not in the inclusive range ‘a’ through ‘s’ or the characters ‘y’ and ‘z’.
\uXXXX \UXXXXXXXX | The character represented by the four-digit hexadecimal Unicode code (XXXX). The character represented by the eight-digit hexadecimal Unicode code (XXXXXXXX). For certain symbol fonts the symbol (glyph) that you see on screen may look related to a different Unicode code than what is actually used for it in the font. The Unicode codes can be viewed by choosing Insert - Special Character, or by using Unicode conversion shortcut.
\N{NOM DEL CARÀCTER UNICODE} | Match the Unicode named character. Some remarkable Unicode named characters are SPACE, NO-BREAK SPACE, SOFT HYPHEN, ACUTE ACCENT, CIRCUMFLEX ACCENT, GRAVE ACCENT. The Unicode character names can be searched and viewed by choosing Insert - Special Character.
| | The infix operator delimiting alternatives. Matches the term preceding the "|" or the term following the "|". For example, "this|that" matches occurrences of both "this" and "that".
{N} | The post-fix repetition operator that specifies an exact number of occurrences ("N") of the regular expression term immediately preceding it must be present for a match to occur. For example, "tre{2}" matches "tree".
{N,M} | The post-fix repetition operator that specifies a range (minimum of "N" to a maximum of "M") of occurrences of the regular expression term immediately preceding it that can be present for a match to occur. For example, "tre{1,2}" matches "tre" and "tree".
{N,} | The post-fix repetition operator that specifies a range (minimum "N" to an unspecified maximum) of occurrences of the regular expression term immediately preceding it that can be present for a match to occur. (The maximum number of occurrences is limited only by the size of the document). For example, "tre{2,}" matches "tree", "treee", and "treeeee".
(...) | The grouping construct that serves three purposes. To enclose a set of ‘|’ alternatives. For example, the regular expression "b(oo|ac)k" matches both "book" and "back". To group terms in a complex expression to be operated on by the post-fix operators: "*", "+" and "?" along with the post-fix repetition operators. For example, the regular expression "a(bc)?d" matches both "ad" and "abcd"; "M(iss){2}ippi" matches "Mississippi". To reference the matched sub string inside the parentheses for later use. The "\N" construct is used in the Find box, the "$N" construct is used in the Replace box. "N" being a digit, the reference to the first match is represented by "\1" in the Find box and by "$1" in the Replace box; "\2" and "$2" reference to the second matched, and so on. For example, the regular expression "(890)xy\1z\1" matches "890xy890z890". With the regular expression "(fruit|truth)\b" in the Find box, and the replacement expression "$1ful" in the Replace box, occurrences of "fruit" and "truth" are replaced with "fruitful" and "truthful" respectively. Note: "\b" prevents "fruitfully" or "truthfully" from matching.
[:alpha:] | Representa un caràcter alfabètic. Useu [:alpha:] per a trobar-ne.
\d [:digit:] | Representa un dígit decimal. Useu [:digit:] per a trobar-ne.
[:alnum:] | Representa un caràcter alfanumèric ([:alpha:] i [:digit:]).
\s [:space:] | Representa un espai (però no altres espais en blanc).
[:print:] | Representa un caràcter imprimible.
[:cntrl:] | Representa un caràcter no imprimible.
[:lower:] | Representa minúscules si l'opció Distingeix entre majúscules i minúscules s'ha seleccionat a Opcions.
[:upper:] | Representa majúscules si l'opció Distingeix entre majúscules i minúscules s'ha seleccionat a Opcions.

Els termes d'expressions regulars es poden combinar per a formar expressions regulars complexes i sofisticades per a cerques, tal com es mostra en els exemples següents.

## Exemples

Expressió | Significat
--- | ---
^$ | Un paràgraf buit. ^ especifica que la partida ha de ser al començament d'un paràgraf $ especifica que una marca de paràgraf o el final d'una cel·la han de seguir la cadena coincident.
^. | El primer caràcter d'un paràgraf. ^ especifica que la partida ha de ser al començament d'un paràgraf . specifies any single character.
e([:digit:])? | Matches "e" by itself or an "e" followed by one digit. e specifies the character "e", [:digit:] especifica qualsevol dígit decimal ? specifies zero or one occurrences of [:digit:].
^([:digit:])$ | Matches a paragraph or cells containing exactly one digit. ^ especifica que la partida ha de ser al començament d'un paràgraf [:digit:] especifica qualsevol dígit decimal $ especifica que una marca de paràgraf o el final d'una cel·la han de seguir la cadena coincident.
^[:digit:]{3}$ | Matches a paragraph or cell containing only three digit numbers ^ especifica que la partida ha de ser al començament d'un paràgraf [:digit:] especifica qualsevol dígit decimal {3} specifies that [:digit:] must occur three times, $ especifica que una marca de paràgraf o el final d'una cel·la han de seguir la cadena coincident.
\bconst(itu|ruc)ció\b | Matches the words "constitution" and "construction" but not the word "constitutional." \b specifies that the match must begin at a word boundary, const specifies the characters "const", ( starts the group, itu specifies the characters "itu", | specifies the alternative, ruc specifies the characters "ruc", ) ends the group, tion specifies the characters "tion", \b specifies that the match must end at a word boundary.

Temes relacionats

Documentació de les expressions regulars de l'ICU (en anglès)

Find & Replace

D'oh! You found a bug (text/swriter/guide/search_regexp.xhp#search_regexp not found).

Cercar i reemplaçar en el Writer

Wiki page about regular expressions in Writer

Wiki page about regular expressions in Calc

Ens cal la vostra ajuda!