我有一个字符串,我想用它Regex
来替换[
to {
,但如果[
被转义,请忽略它,如下所示:
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);