C# Regex 用忽略特定单词替换字符串

C# Regex Replace string with Ignore specific word

我有文件,我想用正则表达式替换固定字符 * : ~ with @,但是它不应该替换(忽略)B~~ 词,因为它需要保持原样。有人对此有想法吗?

输入:

ABCHKLJNKL*dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm:skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK

输出应该是:

ABCHKLJNKL@dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm@skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK

请提供正则表达式,因为我想一步完成。

谢谢

[*:]|(?<!B[~])[~](?![~])

尝试 this.This 应该 it.See demo.Replace @

https://regex101.com/r/tX2bH4/66