gpt4 book ai didi

c# - 使用正则表达式替换字符但不要替换转义字符

转载 作者:行者123 更新时间:2023-11-30 22:18:44 25 4
gpt4 key购买 nike

我有一个字符串,我想使用 Regex[ 替换为 {,但是如果 [ 是转义了,忽略它,像这样:

abc[def\[ghi

abc{def\[ghi

我该怎么做?非常感谢!

最佳答案

使用这个:

Regex regexObj = new Regex(
@"(?<= # Make sure that this is true before the start of the match:
(?<!\\) # There is no single backslash,
(?:\\\\)* # but if there are backslashes, they need to be an even number.
) # End of lookbehind assertion.
\[ # Only then match a bracket",
RegexOptions.IgnorePatternWhitespace);

关于c# - 使用正则表达式替换字符但不要替换转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15942549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com