在文字搜索中使用正则表达式

Regular expressions are special patterns used to find and manipulate text, helping you locate specific information within texts.

note

用正则表达式搜索与用通配符搜索不同。LibreOffice Writer 只支持使用正则表达式搜索。


在文档中查找与替换文字时,可以使用正则表达式。例如,「s.n」可以找到「sun」和「son」。

  1. 选择「编辑 - 查找与替换」。

  2. 点击「更多选项」展开对话框。

  3. 选中「正则表达式」复选框。

  4. 在「查找」框中,输入要查找的关键词与正则表达式。

  5. 点击「查找下一个」或「查找全部」。

正则表达式示例

  1. 代表单个字符的正则表达式是句点 (.)。

  2. The regular expression for a word character \w, and \d for a decimal digit.

  3. 代表零或多个之前字符的正则表达式是星号。例如:「123*」可以找到「12」「123」以及「1233」。

  4. The regular expression to search for zero or more occurrences of any character is a period and asterisk (.*).

  5. The regular expression for one or more occurrences of the previous character is a plus sign (+). For example: "\w+" finds any word, "\d+" any number.

  6. The regular expression for a tab character is \t. More generally, \s stands for all kinds of "spaces", like non-breaking space, carriage return ...

  7. The regular expression for the end of a paragraph is a dollar sign ($). The regular expression for the start of a paragraph is a caret and a period (^.). The regular expression for an empty paragraph is ^$.

批注图标

A search using a regular expression will work only within one paragraph. That is, a \n will match a line break within a paragraph.


请支持我们!