Java Email Validate extractEmail(String string, StringBuffer sb)

Here you can find the source of extractEmail(String string, StringBuffer sb)

Description

extract Email

License

Apache License

Declaration

private static String extractEmail(String string, StringBuffer sb) 

Method Source Code

//package com.java2s;
/*/*from  w ww.  j a v a 2  s  .co  m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private final static Pattern EMAIL = Pattern
            .compile("(?i)([^<@\\s]+@[^@> ]+)");

    private static String extractEmail(String string, StringBuffer sb) {
        Matcher emailMatcher = EMAIL.matcher(string);
        String email = "";
        //TODO: warn if more than one email is found?
        while (emailMatcher.find()) {
            emailMatcher.appendReplacement(sb, "");
            email = emailMatcher.group(1);
        }
        emailMatcher.appendTail(sb);
        return email;
    }
}

Related

  1. checkEmailAddressNoEx(String inEmailAddress)
  2. checkEmailPattern(String email)
  3. checkEmailWithSuffix(String email)
  4. cleanUpEmailAddress(CharSequence address)
  5. containsEmail(String chunk)
  6. extractEmailAddresses(final String text)
  7. format(String emails)
  8. getEmail(String author)
  9. getEmailAddressFromDN(String dn)