Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
OriginalGriff 6-Apr-13 6:21am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Show us the code fragment you use to do the regex, and to try and save the data.
Use the "Improve question" widget to edit your question and provide better information.
_Starbug_ 6-Apr-13 6:41am    
my friend,my problem is just saving matches to a text file just this.i tried more time but nothing.this is my regex code and saving code. string EmailPattern2 = @"(([A-Za-z0-9\.]{3,64})@([A-Za-z0-9\.]{2,10}))"; string EmailPattern3=@"(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)"; string tel2 = @"([1-9]{2}-[0-9]{3}-[0-9]{5})|([0-9]{2}-[0-9]{3}-[0-9]{3}\s[0-9]{2}\s[0-9]{2,10})|([0]{1}[9]{1}[1|3]{1}[0-9]{8})|(\+[0-9]{2,3}[0-9]{10,17})"; //string twopattern = @"(([A-Za-z0-9\.]{3,64})@([A-Za-z0-9\.]{2,10}))|([1-9]{2}-[0-9]{3}-[0-9]{5})|([0-9]{2}-[0-9]{3}-[0-9]{3}\s[0-9]{2}\s[0-9]{2,10})|([0]{1}[9]{1}[1|3]{1}[0-9]{8})|(\+[0-9]{2,3}[0-9]{10,17})"; MatchCollection matchesTel = Regex.Matches(strln, tel2, RegexOptions.Multiline); MatchCollection matchesEmail = Regex.Matches(strln, EmailPattern2,RegexOptions.Multiline); label3.Text = "Emails Found :" + matchesEmail.Count+ "********" + "Telephones Found :" + matchesTel.Count + ""; MatchCollection emaq = Regex.Matches(strln, EmailPattern3); label4.Text = emaq.Count.ToString(); label7.Text = mc.Count.ToString(); File.WriteAllLines(@"C:\Users\Alcatraz\Desktop\emaphonew.txt", Regex.Split(strln, EmailPattern3)); File.WriteAllLines(@"C:\Users\Alcatraz\Desktop\Telephone.txt", Regex.Split(strln, tel2));

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
C#
string input = "hello;there;paul";
File.WriteAllLines(@"D:\Temp\op.txt", Regex.Split(input, ";");
Would produce a file completely lacking in semicolons?
hello
there
paul
I 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...
 
Share this answer
 
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[^]
 
Share this answer
 
v2
Comments
_Starbug_ 6-Apr-13 6:42am    
thank you but my problem is to save finded matches to a text file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900