Module
Contents
Index 🔎︎

# 常規表述式的清單

字元 | 效果/插入項
任意字元 | 除非特別指定，否則表示指定的字元。
. | 表示斷行符或段落斷行符以外的任何單一字元。例如，搜尋術語「sh.rt」會同時傳回「shirt」和「short」兩項。
^ | 只有在搜尋的術語位於段落的開始位置時，才找到此術語。忽略段落開始位置的特殊物件，例如空白欄位或字元鎖定的外框。範例："^Peter"。
$ | 只有在搜尋的術語出現在段落的結束位置時，才找到此術語。忽略段落結束位置的特殊物件，例如空白欄位或字元鎖定的外框。範例："Peter$"。 $ on its own matches the end of a paragraph. This way it is possible to search and replace paragraph breaks.
* | 尋找 "*" 前面的零個或多個字元。例如，"Ab*c" 尋找"Ac"、"Abc"、"Abbc"、"Abbbc" 等等。
+ | 尋找 "+" 前面的一個或多個字元。例如，"AX.+4" 尋找 "AXx4"，而不是 "AX4"。 通常能在段落中找到符合此搜尋樣式的最長的字串。如果段落中包含字串「AX 4 AX4」，則會反白顯示整個段落。
? | 尋找 "?" 前面的零個或其中一個字元。例如，"Texts?" 可找到 "Text" 和 "Texts"，而 "x(ab|c)?y" 可找到"xy"、"xaby" 或 "xcy"。
\ | 會把「\」後的特殊字元解釋為一般字元並非以常規表述式進行搜尋 (除了 \n、\t、\> 與 \< 組合)。例如，使用「tree\.」尋找「tree.」並非「treed」或「trees」。
\n | Represents a line break that was inserted with the Shift+Enter key combination. To change a line break into a paragraph break, enter \n in the Find and Replace boxes, and then perform a search and replace. \n in the Find text box stands for a line break that was inserted with the Shift+Enter key combination. \n in the Replace text box stands for a paragraph break that can be entered with the Enter or Return key.
\t | Represents a tab. You can also use this expression in the Replace box.
\b | Match a word boundary. For example, "\bbook" finds "bookmark" but not "checkbook" whereas "book\b" finds "checkbook" but not "bookmark". The discrete word "book" is found by both search terms.
^$ | 搜尋空白段落。
^. | 搜尋段落中的第一個字元。
& 或 $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.
[abc123] | 代表方括號中的其中一個字元。
[a-e] | Represents any of the characters that are between a and e, including both start and end characters. 這些字元會依其程式碼編號排序。
[a-eh-x] | Represents any of the characters that are between a-e and h-x.
[^a-s] | Represents everything that is not between a and s.
\uXXXX \UXXXXXXXX | Represents a character based on its four-digit hexadecimal Unicode code (XXXX). For obscure characters there is a separate variant with capital U and eight hexadecimal digits (XXXXXXXX). For certain symbol fonts the code for special characters may depend on the used font. You can view the codes by choosing Insert - Special Character.
| | 尋找出現在「|」前面的字詞，也會尋找出現在「|」後面的字詞。例如，「this|that」會尋找「this」和「that」。
{2} | 定義左括號前字元出現的次數。例如，「tre{2}」會尋找並選取「tree」。
{1,2} | 定義左括號前字元可出現的次數上限及下限。例如，「tre{1,2}」會尋找並選取「tre」及「tree」。
{1,} | 定義左括號前的字元可出現的最少次數。例如，"tre{2,}" 會尋找 "tree"、"treee" 與 "treeeee"。
( ) | In the Find box: 將括號中的字元定義為參照。然後，您可以在目前的表示式中使用「\1」表示第一個參照，使用「\2」表示第二個參照，以此類推。 For example, if your text contains the number 13487889 and you search using the regular expression (8)7\1\1, "8788" is found. You can also use () to group terms, for example, "a(bc)?d" finds "ad" or "abcd". In the Replace box: Use $ (dollar) instead of \ (backslash) to replace references. Use $0 to replace the whole found string.
[:alpha:] | Represents an alphabetic character. Use [:alpha:]+ to find one of them.
[:digit:] | Represents a decimal digit. Use [:digit:]+ to find one of them.
[:alnum:] | 表示字母數字字元 ([:alpha:] 和 [:digit:])。
[:space:] | 表示一個空白字元 (而非其他空格字元)。
[:print:] | 表示可列印字元。
[:cntrl:] | 表示非列印字元。
[:lower:] | 如果已選取 [選項] 中的 [區分大小寫]，表示小寫字元。
[:upper:] | Represents an uppercase character if Match case is selected in Options.

For a full list of supported metacharacters and syntax, see ICU Regular Expressions documentation

## 範例

e([:digit:])? -- finds 'e' followed by zero or one digit. Note that currently all named character classes like [:digit:] must be enclosed in parentheses.

^([:digit:])$ -- finds lines or cells with exactly one digit.

您可以合併搜尋項目以組成複雜的搜尋。

### 尋找段落中三位數的數字

^[:digit:]{3}$

^ 表示符合項必須在段落首，

[:digit:] 會找到所有小數位數，

{3} 表示必須剛好是 3 個「數字」，

$ 表示符合項必須結束段落。

相關主題

搜尋和代替

在文字搜尋中使用萬用字元

在 Writer 中尋找與取代

Wiki page about regular expressions in Writer

Wiki page about regular expressions in Calc