-2

How can I scan for potential e-mail addresses in a text file using Java?

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
kiran
  • 22
  • 1
  • 2
  • 1
    Please don't repost, especially when the question is a bad one. You've asked this question twice and a similar one before that -- don't ask what you have to do, **ask about what you don't understand**. – Rafe Kettler Mar 04 '11 at 07:25
  • Read the text file line by line and check each line red by applying the RegEx on it. – Mudassir Mar 04 '11 at 07:26
  • @Mudassir maybe she can use this regex http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html :D – Rafe Kettler Mar 04 '11 at 07:27

2 Answers2

0

read file and use regex to match your pattern with any possible email address.

Tahir
  • 9
  • 2
  • read the complete file line by line. Match each line with the regex. if there is any match, extract it or do whatever you need to fulfil your requirements. – Tahir Mar 04 '11 at 07:42
0

Use regular expressions. This is the one I have used.

(([\w-]+.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,})) ((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]). ([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}| ([a-zA-Z]+[\w-]+.)+[a-zA-Z]{2,4})|^((+\d{1,3}(-| )?(?\d)?(-| )?\d{1,5}) |((?\d{2,6})?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}

Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92