来自正则表达式教程 - 字面字符和特殊字符:
因为我们想要做的不仅仅是简单地搜索字面文本片段,我们需要保留某些字符用于特殊用途。至少有 12 个字符具有特殊含义:
反斜杠 \,脱字符 ^,美元符号 $,句点或点 .,竖线或管道符号 |,问号 ?,星号或星 *,加号 +,左括号 (,右括号 ),左方括号 [,和左花括号 {。这些特殊字符通常被称为“元字符”。大多数字符单独使用时都是错误。
如果你想在正则表达式中将其中任何字符用作字面字符,你需要用反斜杠转义它们。如果你想匹配 1+1=2,正确的正则表达式是 1\+1=2。否则,加号具有特殊含义。
在 PT 中,我们经常需要在正则表达式中使用 \,因为它对我们来说对于 usfms 来说非常基本。因此,要在正则表达式中搜索 \p,你输入 \\p。
(学习转义是有用的,因为即使在这个论坛工具中,某些字符除非你转义它们或使用通过 </> 图标访问的“预格式化文本”功能,否则不会渲染。)
From a Regex Tutorial - Literal Characters and Special Characters:
Because we want to do more than simply search for literal pieces of text, we need to reserve certain characters for special use. There are at least 12 characters with special meanings:
the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ), the opening square bracket [, and the opening curly brace {, These special characters are often called “metacharacters”. Most of them are errors when used alone.
If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign has a special meaning.
And in PT, we often need the \ in a regex, because it is so fundamental for usfms. So to search for \p in a regex, you type \\p.
(It is useful to learn about escaping, as even in this forum-tool, certain characters will not render, unless you either escape them or use the “preformatted text” feature via the </> icon.)
机器翻译自 English