List of usage examples for java.util.regex Matcher matches
public boolean matches()
From source file:com.baasbox.util.Util.java
public static boolean validateEmail(final String hex) { Pattern pattern = Pattern.compile(EMAIL_PATTERN); Matcher matcher = pattern.matcher(hex); return matcher.matches(); }
From source file:guru.bubl.module.model.validator.UserValidator.java
private static boolean isEmailValid(String email) { if (isBlank(email)) return false; Matcher m = email_pattern.matcher(email); return m.matches(); }
From source file:TimeFormatUtil.java
/** * @param seconds//from w w w . jav a2s . c om * @return a string which represents a floating point number with max. 2 * decimals */ public static String formatTimeTo2Digits(double seconds) { String timeString = Double.toString(seconds); int dotPos = timeString.indexOf("."); if (dotPos < 0) return timeString; Pattern p = Pattern.compile("([0-9]{1,})\\.([0-9]{1,})"); Matcher m = p.matcher(timeString); if (!m.matches()) throw new RuntimeException( "WARNING: pattern '" + p.pattern() + "' " + "did not match input '" + timeString + "'"); StringBuilder b = new StringBuilder(m.group(1)); b.append('.'); String afterCommaDigits = m.group(2); if (afterCommaDigits.length() > 2) b.append(m.group(2).substring(0, 2)); else b.append(afterCommaDigits); return b.toString(); }
From source file:anslab2.Test.java
public static boolean typesMatch(String _input, int dataType) { if (dataType == 1) { //parse sa Alphabetic Pattern p = Pattern.compile("^[a-zA-Z]*$"); Matcher m = p.matcher(_input); if (!m.matches()) { JOptionPane.showMessageDialog(null, "Wrong Format! you chose Alphabet"); return false; }/*from w w w . j ava 2 s. co m*/ } else if (dataType == 2) { //parse sa Numeric try { Double.parseDouble(_input); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(null, "Wrong Format! you chose numeric"); return false; } } else if (dataType == 3) { //regex sa String } return true; }
From source file:cn.cuizuoli.gotour.utils.HtmlHelper.java
/** * toList/* w w w.jav a 2s.c o m*/ * @param text * @return */ public static String toList(String text) { String[] lines = StringUtils.split(text, "\r\n"); StringBuffer listBuffer = new StringBuffer(); listBuffer.append("<ul>").append("\n"); for (String line : lines) { Matcher listMatcher = LIST_PATTERN.matcher(line); if (listMatcher.matches()) { String li = listMatcher.group(1) + listMatcher.group(2); if (StringUtils.contains(li, "")) { li = "<strong>" + StringUtils.replace(li, "", "</strong>"); } listBuffer.append("<li>").append(li).append("</li>").append("\n"); } } listBuffer.append("</ul>").append("\n"); return listBuffer.toString(); }
From source file:com.bstek.dorado.util.clazz.TypeInfo.java
public static TypeInfo parse(String className) throws ClassNotFoundException { if (StringUtils.isEmpty(className)) { return null; }/* w ww . j a va 2 s.c o m*/ String typeName = null; boolean aggregated = false; Matcher matcher = AGGREGATION_PATTERN_1.matcher(className); if (matcher.matches()) { typeName = matcher.group(2); aggregated = true; } else { matcher = AGGREGATION_PATTERN_2.matcher(className); if (matcher.matches()) { typeName = matcher.group(1); aggregated = true; } } if (typeName == null) { typeName = className; } return new TypeInfo(ClassUtils.forName(typeName), aggregated); }
From source file:com.thoughtworks.go.server.newsecurity.utils.BasicAuthHeaderExtractor.java
public static UsernamePassword extractBasicAuthenticationCredentials(String authorizationHeader) { if (isBlank(authorizationHeader)) { return null; }/* w w w . j ava2s . c om*/ final Matcher matcher = BASIC_AUTH_EXTRACTOR_PATTERN.matcher(authorizationHeader); if (matcher.matches()) { final String encodedCredentials = matcher.group(1); final byte[] decode = Base64.getDecoder().decode(encodedCredentials); String decodedCredentials = new String(decode, StandardCharsets.UTF_8); final int indexOfSeparator = decodedCredentials.indexOf(':'); if (indexOfSeparator == -1) { throw new BadCredentialsException("Invalid basic authentication credentials specified in request."); } final String username = decodedCredentials.substring(0, indexOfSeparator); final String password = decodedCredentials.substring(indexOfSeparator + 1); return new UsernamePassword(username, password); } return null; }
From source file:edu.jhu.pha.vospace.node.VospaceId.java
/** * Check whether the specified identifier is valid * @param id The identifier to check//from w w w. j av a 2 s.co m * @return whether the identifier is valid or not */ private static boolean validId(URI id) { Matcher m = VOS_PATTERN.matcher(id.toString()); return m.matches(); }
From source file:com.ms.commons.message.utils.MessageUtil.java
/** * ???//from w ww .j a va2 s . c o m * * @param mobilePhone * @return */ public static boolean isValidateMobileNumber(String mobilePhone) { Pattern pattern = Pattern.compile("^((13[0-9])|(14[7])|(15[^4,\\D])|(18[0-9]))\\d{8}$"); Matcher matcher = pattern.matcher(mobilePhone); if (matcher.matches()) { return true; } return false; }
From source file:fi.hsl.parkandride.core.domain.prediction.PredictionRequest.java
static Duration parseRelativeTime(String relativeTime) { Matcher matcher = java.util.regex.Pattern.compile(HHMM_PATTERN).matcher(relativeTime); if (matcher.matches()) { int hours = parseOptionalInt(matcher.group(2)); int minutes = Integer.parseInt(matcher.group(3)); return standardHours(hours).plus(standardMinutes(minutes)); } else {/*from www. j a v a2 s .c o m*/ return Duration.ZERO; } }