Which is the Best Java Web Framework ?

Java Code to find email ids in a string


Code to find email ids in a string using Pattern. 

String text="vivek boy goy vivek@tech.com viv@ek.com sdjs@adjk";
Pattern regex = Pattern.compile("[@]");
Matcher regexMatcher = regex.matcher(text);
int i =0;
int width = 0;
while (regexMatcher.find()) {
     if((regexMatcher.start()-10 > 0) && (regexMatcher.end()+10 < text.length())){
          width=10;
       String[]    substr=text.substring(regexMatcher.start()-width,regexMatcher.end()+width).split(" ");
           for(int j=0;j<substr.length;j++){
                   if(substr[j].contains("@") && (substr[j].contains(".com") ||    substr[j].contains(".net"))){
                                System.out.println(substr[j]);
                           }               
                     }
               } else {
               width=0;
        }
 }

Related Post

Web crawler to get emails and images
http://www.buggybread.com/2013/01/create-your-own-email-and-image.html


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.