來自 Regex 教程 - 字面字元和特殊字元:
因為我們想要做的不僅僅是簡單地搜尋字面文本片段,所以我們需要保留某些字元用於特殊用途。至少有 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