我想替换,
字符串中所有 (逗号) 的实例,例如:
word, synonym, synonym (definition 1, definition2)
我不想触碰任何在 first 之前的内容(
,也不想更改括号内的任何文本 - 我所需要的只是将括号内的所有逗号替换为分号,这样我就会得到类似这样的内容:
word, synonym, synonym (definition 1; definition2)
我尝试\(.*[\, ].*\)
捕获括号中的所有内容,但我不知道如何设置 Notepad++ 来仅替换逗号而不替换其他内容。
答案1
所以您想将括号内的 , 替换为分号?
尝试这个:
Find: \((.*)(,)(.*)\)
Explanation: \( - Literally capture a left bracket
(.*) - Captures everything and groups it until...
(,) - Captures the comma and groups it
(.*) - Captures everything and groups it until...
\) - ... the literal right bracket.
Replace With: \($1;$3\)
Explanation: We replace everything caught above, meaning we need to put in...
\( - The literal left bracket again
$1 - The first group we captured before (everything before ,)
; - Our replacement for the comma, a semi colon
$3 - The third group we captured before (we skipped 2, the comma, and got everything after)
\) - Finally, our literal right bracket again
我本可以使它更准确一些,而是这样做:
Find: \((.*)(?:,)(.*)\)
Explanation: (?:) means the group doesn't capture, so we now replace with:
Replace With: \($1;$2\)
当然是在 REGEX 模式下。
希望这可以帮助。