简体   繁体   English

多行正则表达式不匹配

[英]Multiline regex not matching

I'm trying to get a multi-line regex working with .NET but not having much luck. 我试图让多行正则表达式与.NET一起工作,但运气不佳。 I believe I'm right in thinking that this will match multiple lines, but the third match is always omitted. 我认为我认为这将匹配多行是正确的,但是始终省略第三个匹配项。 I need to capture the recipient and reason fields. 我需要捕获收件人和原因字段。 I know I could do this with a loop and two regexes but I'd prefer a more succinct solution. 我知道我可以使用一个循环和两个正则表达式来做到这一点,但是我更喜欢一个简洁的解决方案。

The regex I'm using is: 我正在使用的正则表达式是:

(.*?)Destination: mobile (\(SMS\))?(\d{10,})(?:.*?)Reason: (.*)

It should match against this text: 它应与此文本匹配:

NON-DELIVERY NOTE

The following message was not delivered:

Addressed to: 01234567890@sms.local
Destination: mobile (SMS)01234567890
Reference number: 155618127W

Reason: Rejected by network operator

在这种情况下,您需要使用RegexOptions.Singleline而不是RegexOptions.Multiline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM