Here you can find the source of parseEmail(String target)
public static String parseEmail(String target)
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**//from w w w. j av a2 s. c o m * Parse the target string, and check is obey the email format or not. If not, return null. */ public static String parseEmail(String target) { target = parseString(target); if (target == null) { return null; } String regexp = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"; Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(target); return matcher.find() ? target : null; } /** * Pre-process the String object. If object is null, return null; otherwise * remove heading and tailing white space. */ public static String parseString(String target) { if (target == null) { return null; } else { return target.trim(); } } }