Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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#_Regex - Fatal编程技术网

C# 正则表达式来提取字符串中的字符

C# 正则表达式来提取字符串中的字符,c#,regex,C#,Regex,我需要提取字符串中的一组字符。我计划使用RegEx.Match方法(c#),但我不清楚要使用的RegEx模式。我想提取一个模式,它以//开头,以…结尾 然后,匹配字符串中的长度需要可变,但起始字符和结束字符将始终相同。在DOS中,我会执行以下操作: //* 但我知道这不是正则表达式的正确语法。尝试使用模式 "//.*?\.\.\." 或 一些代码 string data = @"some codes //to double check... another codes //done... //

我需要提取字符串中的一组字符。我计划使用RegEx.Match方法(c#),但我不清楚要使用的RegEx模式。我想提取一个模式,它以//开头,以…结尾

然后,匹配字符串中的长度需要可变,但起始字符和结束字符将始终相同。在DOS中,我会执行以下操作:

//*

但我知道这不是正则表达式的正确语法。

尝试使用模式

"//.*?\.\.\."

一些代码

string data = @"some codes //to double check...
another codes //done...
//to do...";

MatchCollection matches = Regex.Matches(data, @"//(.*?)\.\.\.");
foreach (Match m in matches) {
    print(m.Groups[1].Value);
}
结果

to double check
done
to do
这些仍然与“abc//test…test”匹配
to double check
done
to do