Here you can find the source of getEmail(String author)
Parameter | Description |
---|---|
author | string containing author and possibly email address. |
public static String getEmail(String author)
//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; } }