Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试替换>字符换行符,但无法找出正则表达式部分。
>
我想:
"<StartTag>"
替换为:
"<StartTag>\n"
但不是:
"</EndTag>\n"
当我使用tags_string.Replace(">", "\n")时,它会替换两者。
tags_string.Replace(">", "\n")
任何人都可以帮助使用正则表达式,以便我可以使用它Regex.Replace()来处理 EndTag 案例吗?
Regex.Replace()
您可以使用以下模式来匹配开始标签:
(<[^/][^>]*>)
然后将其替换为$1\n.
$1\n
Regex.Replace(yourText, @"(<[^/][^>]*>)", "$1\n");
考虑...
字符串输出 = Regex.Replace(input, @"(?<=\<\w*)>", @">\n");