正则表达式模式提取行

时间:2015-05-30 05:29:00

标签: regex vb.net

我有如下文字文件:

some text 402115000518432  
402115000518432  97517518878      IDLE
some text
...
some text 402115001509990  
402115001509990  97517490827      IDLE
...

我想在excel文件中以40211“开始”整行。期望的输出:

402115000518432  97517518878      IDLE
402115001509990  97517490827      IDLE

我正在尝试使用以下代码:

Dim pattern = "(?<=\s*)40211[^\s]*"
Dim i = 1

For Each line In File.ReadLines(RichTextBox1.Text)
            Dim match = Regex.Match(line, pattern)


            If match.Success Then
                sheet.Cells(i, 1).Value = match.Value
                i += 1
            End If
        Next

但是输出只是以40211开头的值,而不是以40211开头的整行。感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
fstream file;
file.open("abc.txt",ios::app);
file<<"hello";
file.close();
return 0;
}
你几乎搞砸了。只需重复使用 pattern = "^(40211)" If match.Success Then sheet.Cells(i, 1).Value = line i += 1 End If 变量。

相关问题