Here you can find the source of getFirstEmailAddr(String s)
null
if not found.
Parameter | Description |
---|---|
s | a parameter |
public static String getFirstEmailAddr(String s)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String REGEX_EMAIL = "[\\w\\.%\\+-]+@[\\w\\.%\\+-]+\\.[A-Za-z]+"; private static Pattern patternEmail = null; /**/*www . j a va 2s.c o m*/ * Returns the first email address found in the given string or <code>null</code> if not found. * @param s * @return */ public static String getFirstEmailAddr(String s) { if (s == null) { return null; } if (patternEmail == null) { patternEmail = Pattern.compile(REGEX_EMAIL); } Matcher matcher = patternEmail.matcher(s); if (matcher.find()) { return matcher.group(); } else { return null; } } }