List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static String getAttributeNameFromColName(String tableName) { Pattern p = Pattern.compile("_+(\\w?)"); Matcher m = p.matcher(tableName); StringBuffer sb = new StringBuffer(); while (m.find()) { if (m.start() != 0) m.appendReplacement(sb, m.group(1).toUpperCase()); else/*from w w w . j a va 2 s. co m*/ m.appendReplacement(sb, m.group(1).toLowerCase()); } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
/** * Get the total hrs logged this pay period. * * @param page the raw html of the user's timecard page * @return A double representing the total hours logged this pay period by the user. *//*ww w .j av a2s. c om*/ protected static double getTotalsHrs(String page) { double total = 0; try { Pattern pattern = Pattern.compile("(?i)(<div.*?>)(" + TOTAL_STR + ")(.*?)(</div>)"); Matcher matcher = pattern.matcher(page); if (matcher.find()) { String totalStr = matcher.group(3); if (!(totalStr == null || totalStr.trim().length() == 0)) { total = Double.parseDouble(totalStr); } } } catch (Exception e) { Log.w(TAG, e.toString()); } return total; }
From source file:Main.java
public static String changeED2K(String url) { // TODO Auto-generated method stub Pattern pat = Pattern/* w w w. ja v a 2s. com*/ .compile("ed2k:\\/\\/\\|file\\|([^\\|]+?)\\|(\\d+)\\|([A-Z0-9]{32})\\|(h=[A-Z0-9]{32}\\|)?\\/?"); Matcher mat = pat.matcher(url); // System.out.println(url); if (mat.find()) { String name = "" + mat.group(1); if (name.contains(".")) { String temp = "1" + name.substring(name.lastIndexOf(".")); url = url.replace(name, temp); // System.out.println(url); } } if (url.startsWith("magnet:?xt=urn:btih:") && url.contains("&")) { url = url.substring(0, url.indexOf("&")).toLowerCase(); } return url; }
From source file:Main.java
public static List<String> listAvailableIosPlatformVersions() { List<String> results = new ArrayList<String>(); try {/*from w ww .j a va 2 s . c om*/ ProcessBuilder pb = new ProcessBuilder("xcodebuild", "-showsdks"); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; Pattern pattern = Pattern.compile("-sdk iphoneos(([0-9]+.?)+)"); while ((line = reader.readLine()) != null) { Matcher m = pattern.matcher(line); while (m.find()) { results.add(m.group(1)); } } } catch (Throwable t) { } return results; }
From source file:Main.java
public static String getErrorMsg(String response) { Pattern errorPattern = Pattern.compile("<div class=\"problem\">(.*)</div>"); Matcher errorMatcher = errorPattern.matcher(response); String errorContent;/*from w w w .ja v a 2 s . com*/ if (errorMatcher.find()) { errorContent = errorMatcher.group(1).replaceAll("<[^>]+>", ""); } else { errorContent = null; } return errorContent; }
From source file:Main.java
public static double parseCoordinate(CharSequence string) { int sign = 1; final Matcher negsignMatcher = PAT_NEGSIGN.matcher(string); if (negsignMatcher.find()) { sign = -1;//w ww . ja va2 s . c o m } final Matcher signMatcher = PAT_SIGN.matcher(string); string = signMatcher.replaceAll(""); final Matcher dmsMatcher = PAT_COORD_COMPONENT.matcher(string); double degrees = 0.0; for (double scale = 1.0; scale <= 3600.0 && dmsMatcher.find(); scale *= 60.0) { degrees += Double.parseDouble(dmsMatcher.group(1)) / scale; } return sign * degrees; }
From source file:Main.java
/** * Check of the balanced tags sup/sub//from w w w . jav a 2 s. c o m * * @param snippet * @return <code>true</code> if balanced, <code>false</code> otherwise */ public static boolean isBalanced(String snippet) { if (snippet == null) return true; // ???? Stack<String> s = new Stack<String>(); Matcher m = SUBS_OR_SUPS.matcher(snippet); while (m.find()) { String tag = m.group(1); if (tag.toLowerCase().startsWith("su")) { s.push(tag); } else { if (s.empty() || !tag.equals("/" + s.pop())) { return false; } } } return s.empty(); }
From source file:Main.java
public static String getDynamicPassword(String str) { Pattern continuousNumberPattern = Pattern.compile("[0-9\\.]+"); Matcher m = continuousNumberPattern.matcher(str); String dynamicPassword = ""; while (m.find()) { if (m.group().length() == 4) { dynamicPassword = m.group(); }//w w w. j ava 2s . c om } return dynamicPassword; }
From source file:com.offbynull.portmapper.common.RegexUtils.java
/** * Finds all IPv4 addresses in a block of text. * @param text block of text to search in * @return all IPv4 addresses in {@code text} * @throws NullPointerException if any argument is {@code null} *//*from w w w .j av a2s. c o m*/ public static List<String> findAllIpv4Addresses(String text) { Validate.notNull(text); List<String> ret = new LinkedList<>(); Matcher matcher = IPV4_PATTERN.matcher(text); while (matcher.find()) { ret.add(matcher.group(0)); } return ret; }
From source file:Main.java
public static String getQueryPageUrl(String url, int inc) { if (url == null) { return null; }//w w w . j a v a 2s . c o m if (!url.contains("nicovideo.jp/search/")) { return null; } String ret = null; Matcher matcher = pagePattern.matcher(url); if (matcher.find()) { String _u1 = matcher.group(1); String _p = matcher.group(2); String _u2 = matcher.group(3); int page = 1; try { page = Integer.parseInt(_p) + inc; } catch (NumberFormatException e) { } if (0 < page) { ret = _u1 + page + _u2; } } else { int page = 1 + inc; if (0 < page) { if (url.contains("?")) { ret = url + "&page=" + page; } else { ret = url + "?page=" + page; } } } return ret; }