更新时间:2023-11-13 19:38:52
使用正则表达式:(?< = MessageContent :)。*?(?= MessageContentEnd:)
每个匹配将是标题和预告片之间的完整内容:// 使用System.Text.RegularExpressions;
/// < 摘要 >
/// 为C#开发的正则表达式:星期四,2015年7月16日,01:39:25 PM
/// 使用Expresso版本:3.0.3634,http://www.ultrapico.com
///
/// 正则表达式的描述:
///
/// 匹配前缀但将其从捕获中排除。 [MessageContent:]
/// MessageContent:
/// MessageContent:
/// 任意字符,任意数量的重复,尽可能少
/// 匹配后缀但将其从捕获中排除。 [MessageContentEnd:]
/// MessageContentEnd:
/// MessageContentEnd:
///
///
/// < / summary >
public 静态正则表达式正则表达式= 新正则表达式(
(?< = MessageContent :)。*?(?= MessageContentEnd :),
RegexOptions.IgnoreCase
| RegexOptions.Multiline
|正则表达式Options.Singleline
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
// 捕获InputText中的所有匹配项
MatchCollection ms = regex.Matches (inputText的);
How read the line between two substring in c#
MessageContent: =Current Status: XXXXXXXXXXXXXXXX.
User Experience: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Customer Impact: XXXXXXXXXXXXXXX.
Incident Start Time: Wednesday, July 15, 2015, at 9:25 PM UTC
Preliminary Root Cause: XXXXXXXXXXXXXXXXXXXXXXXXX.
Next Update by: Thursday, July 16, 2015, at 2:30 AM
MessageContentEnd:
I need to get the values between MessageContent and MessageContentEnd:
Use a regex:(?<=MessageContent:).*?(?=MessageContentEnd:)
Each match will be the complete content between the header and trailer:// using System.Text.RegularExpressions; /// <summary> /// Regular expression built for C# on: Thu, Jul 16, 2015, 01:39:25 PM /// Using Expresso Version: 3.0.3634, http://www.ultrapico.com /// /// A description of the regular expression: /// /// Match a prefix but exclude it from the capture. [MessageContent:] /// MessageContent: /// MessageContent: /// Any character, any number of repetitions, as few as possible /// Match a suffix but exclude it from the capture. [MessageContentEnd:] /// MessageContentEnd: /// MessageContentEnd: /// /// /// </summary> public static Regex regex = new Regex( "(?<=MessageContent:).*?(?=MessageContentEnd:)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); // Capture all Matches in the InputText MatchCollection ms = regex.Matches(InputText);