gpt4 book ai didi

c# - 如何使用 C# Regex 获取最后一场比赛

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:27 26 4
gpt4 key购买 nike

<分区>

我正在尝试使用 Regex 使用以下代码读取大型文本文件中的最后一个序列号。每行文本开头的文本文件中的序列号前后有两个空格。如果文件太大,这需要相当长的时间。是否可以从文件末尾到开头读取文本文件,以便第一次单独使用 Match 进行捕获就能得到答案并减少在 c# 中花费的时间。提前致谢。

string contents = File.ReadAllText(path);
string pattern = @"(?<=\s{2}\d{1,7}(?=\s{2})";
MatchCollection matches = Regex.Matches(contents, pattern);
string lastmatch = string.Empty;
foreach (Match s in matches)
{
lastmatch = s.Groups[0].ToString();
}
MessageBox.Show(lastmatch);

文本文件看起来像。

  1  Blah Blah Blah.  
2 Ding Dong Bell.
3 Hello, how are you.
4 My name is Unnikrishnan.
5 You are a very good friend.

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com