我想用C#正则表达式替换字符串匹配特定模式。我用Regex.Replace Function尝试了各种正则表达式,但没有一个为我工作。任何人都可以帮助我建立正确的正则表达式来替换部分字符串。用C#正则表达式替换字符串模式
这是我的输入字符串。正则表达式应该匹配以<message Severity="Error">Password will expire in 30 days
开头的字符串,然后是任何字符(甚至是新行字符),直到它找到结束</message>
标记。如果正则表达式找到匹配的模式,那么它应该用空字符串替换它。
输入字符串:
<message Severity="Error">Password will expire in 30 days.
Please update password using following instruction.
1. login to abc
2. change password.
</message>
正则表达式往往是用于解析XML一个糟糕的选择。我建议使用像“XDocument”这样的XML解析器。 – Oded 2013-04-23 19:05:16
你的'Regex.Replace'函数是什么样的?当你跑他们时发生了什么? – 2013-04-23 19:07:59
我明白了,但我们需要去除基于正则表达式格式提供的运行时配置信息。 – apdev 2013-04-23 19:08:21