C# 在C中通过正则表达式获取子字符串#
我有上面的字符串,并希望提取fkhan19注释之间的文本。。。。mzaighum的评论 如何通过正则表达式实现这一点。您可以使用C# 在C中通过正则表达式获取子字符串#,c#,regex,C#,Regex,我有上面的字符串,并希望提取fkhan19注释之间的文本。。。。mzaighum的评论 如何通过正则表达式实现这一点。您可以使用 string string1 = @"Comments by fkhan19 on Nov 01, 2018: 'ok' Comments by mzaighum on Oct 31, 2018: 'Rs.12,000,000 available in Gas is recommended for reallocation to Gen. Fuel. " 或 第
string string1 = @"Comments by fkhan19 on Nov 01, 2018: 'ok' Comments by mzaighum on Oct 31, 2018: 'Rs.12,000,000 available in Gas is recommended for reallocation to Gen. Fuel. "
或
第一种模式的解释(第二种模式非常相似):
[Cc]
-匹配c
或c
omments by
-逐字匹配omments by
[^]+
-匹配空格以外的一个或多个字符
(.+?)
-匹配一个或多个任意字符(非贪婪)
(?=[Cc]omments by |$)
-积极前瞻:确保以下是模式[Cc]omments by
(如上所述)或字符串结尾$
您希望在2018年11月1日时:“确定”还是'ok'
?
[Cc]omments by [^ ]+(.+?)(?=[Cc]omments by|$)
[Cc]omments by [^ ]+(.+?)(?=[Cc]omments by)