将正则表达式匹配到文本文件的问题 [英] problem of writing regex finded matches to a text file
问题描述
大家好,
在我的表单中点击按钮我读了一个文本文件,里面有电子邮件地址和电话号码。使用正则表达式类和模式我可以知道匹配的数量我的模式。但我不能将这些匹配写入另一个文本文件。请帮忙?
你确实意识到Regex.Split功能的作用,不要''你呢?它提取匹配的数据并拆分输入字符串的其余部分?
所以
string input = hello; there; paul;
File.WriteAllLines( @ D:\Temp \op.txt, Regex.Split(输入, ;);会生成一个文件完全没有分号?
你好
有
paul我怀疑你的描述中你想要提取电子邮件和电话号码:所以使用您之前创建的MatchCollections,几个
foreach
循环并从那里写入文本...
你应该尝试一些工具来设计你的正则表达式:
Expresso - 用于构建和测试正则表达式的工具 [ ^ ]
编辑:
你应该阅读e关于此主题的Microsoft文档:
http://msdn.microsoft.com /en-us/library/s2tte0y1.aspx [ ^ ]
http://msdn.microsoft。 com / en-us / library / 3det53xh.aspx [ ^ ]
hi all,
in my form by clicking a button i read a text file that have email address and telephone number in it.by using regex class and a pattern i can know count of matches with my pattern.but i do not can write this matches to another text file.please help?
You do realize what the Regex.Split function does, don''t you? That it extracts the matched data and splits the rest of the input string?
So
string input = "hello;there;paul"; File.WriteAllLines(@"D:\Temp\op.txt", Regex.Split(input, ";");Would produce a file completely lacking in semicolons?
hello there paulI suspect from your description that you want to extract the emails and phone numbers: so use the MatchCollections you created earlier, a couple of
foreach
loops and write the text from there...
You shoulod try some tools to design your regex:
Expresso - A Tool for Building and Testing Regular Expressions[^]
Edit:
You should read the Microsoft documentation on the subject:
http://msdn.microsoft.com/en-us/library/s2tte0y1.aspx[^]
http://msdn.microsoft.com/en-us/library/3det53xh.aspx[^]
这篇关于将正则表达式匹配到文本文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!