Java Email Validate getEmail(String author)

Here you can find the source of getEmail(String author)

Description

Get email address of the author.

License

Open Source License

Parameter

Parameter Description
author string containing author and possibly email address.

Return

email address of the author or full author string if the author string does not contain an email address.

Declaration

public static String getEmail(String author) 

Method Source Code

//package com.java2s;
/*// www  . j  av  a2s.c o m
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * See LICENSE.txt included in this distribution for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at LICENSE.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

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

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

    /**
     * Get email address of the author.
     *
     * @param author string containing author and possibly email address.
     * @return email address of the author or full author string if the author
     * string does not contain an email address.
     */
    public static String getEmail(String author) {
        Matcher emailMatcher = EMAIL_PATTERN.matcher(author);
        String email = author;
        if (emailMatcher.find()) {
            email = emailMatcher.group(1).trim();
        }

        return email;
    }
}

Related

  1. cleanUpEmailAddress(CharSequence address)
  2. containsEmail(String chunk)
  3. extractEmail(String string, StringBuffer sb)
  4. extractEmailAddresses(final String text)
  5. format(String emails)
  6. getEmailAddressFromDN(String dn)
  7. getEmailListStr(String tempStr)
  8. getEmails(String str)
  9. getFirstEmailAddr(String s)