/** * See {@link hudson.FilePath#isAbsolute(String)}. * @param path String representing <code> Platform Specific </code> (unlike FilePath, which may get Platform agnostic paths), may not be null * @return true if String represents absolute path on this platform, false otherwise */ public static boolean isAbsolute(String path) { Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*"); return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches(); }
/** * Given a String the method uses Regex to check if the String only contains punctuation characters * * @param s a String to check using regex * @return true if the String is valid */ public static boolean isPunct(String s){ Pattern p = Pattern.compile("^[\\p{Punct}]+$"); Matcher m = p.matcher(s); return m.matches(); }
/** * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used * in Android) requires a successful match in order to generate a {@code MatchResult}: * http://goo.gl/5VQFmC */ private static MatchResult newMatchResult() { Matcher matcher = Pattern.compile(".").matcher("X"); matcher.find(); return matcher.toMatchResult(); }
/** * Given a String the method uses Regex to check if the String only contains alphabet characters * * @param s a String to check using regex * @return true if the String is valid */ public static boolean isAlpha(String s){ Pattern p = Pattern.compile("^[\\p{Alpha}\\s]+$"); Matcher m = p.matcher(s); return m.matches(); }
/** * Given a String the method uses Regex to check if the String only contains alphanumeric characters * * @param s a String to check using regex * @return true if the String is valid */ public static boolean isAlphanumeric(String s){ Pattern p = Pattern.compile("^[\\p{Alnum}\\s\\.]+$"); Matcher m = p.matcher(s); return m.matches(); }
private static void assertContainsRegex(String expectedRegex, String actual) { Pattern pattern = Pattern.compile(expectedRegex); Matcher matcher = pattern.matcher(actual); if (!matcher.find()) { String actualDesc = (actual == null) ? "null" : ('<' + actual + '>'); fail("expected to contain regex:<" + expectedRegex + "> but was:" + actualDesc); } } }
/** * Given a String the method uses Regex to check if the String only contains numeric characters * * @param s a String to check using regex * @return true if the String is valid */ public static boolean isNumeric(String s){ Pattern p = Pattern.compile("^[\\p{Digit}\\s\\.]+$"); Matcher m = p.matcher(s); return m.matches(); }
/** * Given a String the method uses Regex to check if the String looks like an acronym * * @param s a String to check using regex * @return true if the String is valid */ public static boolean isAcronym(String s){ Pattern p = Pattern.compile("^[\\p{Upper}]+$"); Matcher m = p.matcher(s); return m.matches(); }
private String getFileName (String line) { Pattern pattern = Pattern.compile("(.*):([0-9])+:[0-9]+:"); Matcher matcher = pattern.matcher(line); matcher.find(); String fileName = matcher.groupCount() >= 2 ? matcher.group(1).trim() : null; if (fileName == null) return null; int index = fileName.indexOf(" "); if (index != -1) return fileName.substring(index).trim(); else return fileName; }