List of usage examples for java.util.regex Matcher matches
public boolean matches()
From source file:Main.java
public static String encode(String str) { if (str == null) { return null; }//from w ww .j ava2 s.co m Matcher gtMatcher = gt.matcher(str); if (gtMatcher.matches()) { str = gtMatcher.replaceAll(">"); } Matcher ltMatcher = lt.matcher(str); if (ltMatcher.matches()) { str = ltMatcher.replaceAll("<"); } Matcher quotMatcher = quot.matcher(str); if (quotMatcher.matches()) { str = quotMatcher.replaceAll("""); } Matcher ampMatcher = amp.matcher(str); if (ampMatcher.matches()) { str = ampMatcher.replaceAll("&"); } return str; }
From source file:Main.java
/** * Verifies that an OID is in dot-separated string format. * TODO: Make this more robust.//from w w w. j a v a 2s.com * * @param oid OID to verify * @return true if OID is valid, false otherwise */ public static boolean verifyOid(String oid) { // Pattern to match '.' separated Oid string format Pattern oidPattern = Pattern.compile("^([0-9]+.{1})+[0-9]+$"); Matcher oidIN = oidPattern.matcher(oid); if (oidIN.matches()) { return true; } else { return false; } }
From source file:Main.java
/** * Given a path of the form <code>{doc|document}('<i>aDoc.xml</i>')<i>/aPath</i></code>, it divides it into the doc and the path * @param pathWithDoc a path starting with the XPath 'doc' function or the XSLT 'document' function. * @return a string array such that array[0]=<i>docPath</i>, array[1]=<i>path</i> and array[2]=<i>pathWithoutRootElement</i> *//*from w w w .j av a 2s. c o m*/ public static String[] divideDocAndPath(String pathWithDoc) { String[] result = new String[3]; final String REGEXP_SEARCH = "^(doc|document)\\('(?<docName>.+)'\\)(?<path>/[^\\[\\]/]+(\\[.+\\])?(?<pathWithoutRoot>/.+))$"; Pattern patternToSearch = Pattern.compile(REGEXP_SEARCH); Matcher matcher = patternToSearch.matcher(pathWithDoc); matcher.matches(); result[0] = matcher.group("docName"); result[1] = matcher.group("path"); result[2] = matcher.group("pathWithoutRoot"); return result; }
From source file:Main.java
public static boolean isEmail(String email) { if (isEmpty(email, true)) return false; Pattern pattern = Pattern.compile("^([a-z]|[A-Z]|[0-9])+@([a-z]|[A-Z]|[0-9])+\\.([a-z]|[A-Z]){2,}$"); Matcher matcher = pattern.matcher(email.trim()); return matcher.matches(); }
From source file:Main.java
/** * Validates an email based on regex -/* w ww .j av a2 s . co m*/ * "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + * "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; * * @param email * String containing email address * @return True if the email is valid; false otherwise. */ public static boolean isEmailValid(String email) { boolean isValid = false; try { // Initialize reg ex for email. String expression = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; CharSequence inputStr = email; // Make the comparison case-insensitive. Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) { isValid = true; } } catch (NullPointerException e) { e.printStackTrace(); } return isValid; }
From source file:Main.java
/** check if string is valid ipv4 */ public static boolean validIP(String ip) { if (ip == null || ip.isEmpty()) return false; ip = ip.trim();// ww w.j a va 2 s .c o m if ((ip.length() < 6) & (ip.length() > 15)) return false; try { Pattern pattern = Pattern.compile( "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); Matcher matcher = pattern.matcher(ip); return matcher.matches(); } catch (Exception e) { return false; } }
From source file:Main.java
public static final boolean isMobilePhoneNumber(CharSequence target) { if (target != null || TextUtils.isEmpty(target) == false) { Matcher numberMatcher = mauritianMobilePhoneNumber.matcher(target); return numberMatcher.matches(); }//from ww w . ja v a2 s. c o m return false; }
From source file:io.pivotal.kr.load_gen.Main.java
private static String stripSurroundingQuotes(String expr) { Matcher matcher = leadingQuotePattern.matcher(expr); if (matcher.matches()) { String leadingQuoteStripped = matcher.group(1); matcher = tailingQuotePattern.matcher(leadingQuoteStripped); if (matcher.matches()) { return matcher.group(1); } else {/*from ww w . j ava 2 s. c o m*/ return leadingQuoteStripped; } } else { return expr; } }
From source file:Main.java
public static boolean isPhoneNumber(String phoneNum) { if (isEmpty(phoneNum, true)) return false; Pattern pattern = Pattern.compile("^1\\d{10}$"); Matcher matcher = pattern.matcher(phoneNum.trim()); return matcher.matches(); }
From source file:Main.java
public static long toTime(String expr) { Pattern p = Pattern.compile("(-?)([0-9][0-9]):([0-9][0-9]):([0-9][0-9])([\\.:][0-9][0-9]?[0-9]?)?"); Matcher m = p.matcher(expr); if (m.matches()) { String minus = m.group(1); String hours = m.group(2); String minutes = m.group(3); String seconds = m.group(4); String fraction = m.group(5); if (fraction == null) { fraction = ".000"; }// ww w .j ava 2 s .c om fraction = fraction.replace(":", "."); long ms = Long.parseLong(hours) * 60 * 60 * 1000; ms += Long.parseLong(minutes) * 60 * 1000; ms += Long.parseLong(seconds) * 1000; if (fraction.contains(":")) { ms += Double.parseDouble("0" + fraction.replace(":", ".")) * 40 * 1000; // 40ms == 25fps - simplifying assumption should be ok for here } else { ms += Double.parseDouble("0" + fraction) * 1000; } return ms * ("-".equals(minus) ? -1 : 1); } else { throw new RuntimeException("Cannot match '" + expr + "' to time expression"); } }