我想用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