我可以\±*\¦
在 Microsoft Word 中使用通配符搜索所有字符,如下所示:±sample word1¦ ±sample word2¦
\±*\¦
匹配 ± 和 ¦ 之间的所有字符。当我想用 ( ) 或任何其他字符替换 ± ¦ 时,我会使用以下命令:(^&)
返回结果为:(±sample word1¦)。
使用 MS Word 一切正常,但我还没有找到文本编辑器的正则表达式的等效项(我使用 sublimetext 和 notepad++)
请帮我!
答案1
Notepad++ 使用 boost 正则表达式,匹配 0 个或更多你必须使用的字符.*
- Ctrl+H
- 找什么:
±.*?¦
- 用。。。来代替:
\($0\)
- 检查环绕
- 检查正则表达式
- 取消选中
. matches newline
- Replace all
解释:
± # ± character, doesn't need to be escaped as it hasn't special meaning in regex
.*? # 0 or more any character, but newline, not greedy
¦ # ¦ character, doesn't need to be escaped as it hasn't special meaning in regex. But if you use pipe `|` character then, you have to escape it: \|
替代品:
\( # opening parenthesis, have to be escaped in Notepad++
$0 # the whole match
\) # closing parenthesis, have to be escaped in Notepad++
鉴于:
±sample word1¦ ±sample word2¦
给定示例的结果:
(±sample word1¦) (±sample word2¦)
屏幕截图: