Cannot get regular expression work correctly with multiline

前端 未结 4 2231
南笙
南笙 2020-12-15 06:16

I have a quite big XML output from an application. I need to process it with my program and then feed it back to the original program. There are pieces in this XML which nee

4条回答
  •  既然无缘
    2020-12-15 06:57

    If you're still having problems with this, it may be because you are using AND with your RegexOptions instead of OR.

    This code is wrong and will pass zero as the second parameter to the constructor:

    Regex regExp = new Regex(@"(.*?)",
    RegexOptions.Multiline & RegexOptions.IgnorePatternWhitespace & RegexOptions.CultureInvariant);
    

    This code is correct (as far as using multiple RegexOptions flags):

    Regex regExp = new Regex(@"(.*?)",
    RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);
    

提交回复
热议问题