Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中通过正则表达式获取子字符串#_C#_Regex - Fatal编程技术网

C# 在C中通过正则表达式获取子字符串#

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. " 或 第

我有上面的字符串,并希望提取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. "

第一种模式的解释(第二种模式非常相似):

[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)