• Post Reply Bookmark Topic Watch Topic
  • New Topic

File proccessing  RSS feed

 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have a big text file i want to write a code to extract only the email id's in that text file.

help how can i do that in the easy way. which API i can use.

thanks
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use java.util.regex.Pattern. I have not tested this expression, but try it.

^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.io package has lots of classes that help with reading text files. The simplest example of how to read text files line by line is probably this one.

To advise you further we would need to know more about the format of this file - what is its internal structure, and how can you recognize where the email address is? Or do you simply want to extract all email addresses, regardless of where they occur in the file? If the latter, you may want to search through the lines of the file using a regular expression that describes email address (something like "^\\S+@([-\\w]+\\.){1,4}[a-z]{2,6}$" may be a starting point).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!