Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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#-Regex字幕文件(.srt)以获取文本内容?_C#_Regex - Fatal编程技术网

C#-Regex字幕文件(.srt)以获取文本内容?

C#-Regex字幕文件(.srt)以获取文本内容?,c#,regex,C#,Regex,我有一个srt文件 1 00:00:07,000 --> 00:00:09,000 Time to amaze the world.. create by Hazy 2 00:00:11,000 --> 00:00:12,200 show them 3 00:00:15,000 --> 00:00:16,500 an impossible feat 我想获取文本内容 Time to amaze the world.. create by Hazy, show them,

我有一个srt文件

1
00:00:07,000 --> 00:00:09,000
Time to amaze the world..
create by Hazy

2
00:00:11,000 --> 00:00:12,200
show them

3
00:00:15,000 --> 00:00:16,500
an impossible feat
我想获取文本内容

Time to amaze the world..
create by Hazy,
show them,
an impossible feat
我的正则表达式:

string[] souceSrt = Regex.Split(inputText.Text, @"\n*\d+\n\d\d:\d\d:\d\d,\d\d\d --> \d\d:\d\d:\d\d,\d\d\d\n");
但它不起作用。我应该怎么做???

使用


除非我遗漏了什么,否则你不想要的行将永远不会有字母字符。

你的方法不错,我认为你的模式不起作用,因为换行符(可能是CRLF):


请注意,第一种方法比搜索所有包含字母的行更安全(想象一个字符写着“你多大了?”)

在使用正则表达式时,你不应该在某个地方有多行标志吗?我认为使用
File.ReadAllLines
可能更容易,然后跳过你不感兴趣的行,我不明白为什么有些人对这篇文章投了反对票。这个解决方案只适用于英语字幕。如果我们有其他语言,如阿拉伯语或波兰语字幕怎么办。如果我们有其他语言,如阿拉伯语或波兰语字幕怎么办时间到了。
string strRegex = @"^.*([a-zA-Z]).*$";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline);

foreach (Match myMatch in myRegex.Matches(strTargetString))
{
   if (myMatch.Success)
   {
     //grab line
   }
}
(?:\r?\n)*\d+\r?\n\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}\r?\n