List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
static boolean isTheUpdateForMe(File path) { JarFile jar;/*from w ww. j av a 2s . c o m*/ try { jar = new JarFile(path); } catch (IOException e) { // TODO Auto-generated catch block return false; } ZipEntry entry = jar.getEntry("system/build.prop"); final String myDevice = "ro.product.device=" + Build.DEVICE; boolean finded = false; if (entry != null) { try { InputStreamReader bi = new InputStreamReader(jar.getInputStream(entry)); BufferedReader br = new BufferedReader(bi); String line; Pattern p = Pattern.compile(myDevice); do { line = br.readLine(); if (line == null) { break; } Matcher m = p.matcher(line); if (m.find()) { finded = true; break; } } while (true); bi.close(); } catch (IOException e) { // TODO Auto-generated catch block } } try { jar.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return finded; }
From source file:Main.java
public static String getMD5FileName(String filePathName) { if (!TextUtils.isEmpty(filePathName)) { Matcher matcher = sPattern.matcher(filePathName); if (matcher.find()) { return matcher.group(1) + matcher.group(2); }/*from w w w . j ava2s .c om*/ } return getMD5Value(filePathName); }
From source file:com.inkubator.hrm.util.StringUtils.java
public static boolean isContain(String source, String subItem) { String pattern = "\\b" + subItem + "\\b"; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(source); return m.find(); }
From source file:com.thoughtworks.go.util.StringUtil.java
public static String matchPattern(String regEx, String s) { Pattern pattern = Pattern.compile(regEx); Matcher matcher = pattern.matcher(s); if (matcher.find()) { return matcher.group(1); }//from ww w . j av a2 s . c o m return null; }
From source file:Main.java
public static List<String> getImgSrcList2(String htmlStr) { String IMGURL_REG = "objURL\":\"(http://).*?((.jpg)|(.jpeg)|(.png)|(.JPEG))"; Matcher matcher = Pattern.compile(IMGURL_REG).matcher(htmlStr); List<String> listImgUrl = new ArrayList<String>(); while (matcher.find()) { listImgUrl.add(matcher.group().replace("objURL\":\"", "")); }/*from ww w .jav a 2s. com*/ return listImgUrl; }
From source file:Main.java
public static int getLengthOfLongestWord(String string) { int longestWordLength = 0; Matcher m = Pattern.compile("\\s*(\\S+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(string); while (m.find()) { longestWordLength = Math.max(longestWordLength, m.group(1).length()); }//from ww w . j a va2s. c o m return longestWordLength; }
From source file:edu.cmu.sv.modelinference.common.formats.st.STConfig.java
public static GridPartitions extractGridPartitions(String optionString) throws ParseException { GridPartitions parts = new GridPartitions(); parts.horiz = STModelInferer.DEF_PARTITIONS; parts.vert = STModelInferer.DEF_PARTITIONS; String optionStr = optionString.trim(); String regex = "([0-9]+)x?([0-9]+)?"; Matcher dimPatMatcher = Pattern.compile(regex).matcher(optionStr); if (dimPatMatcher.find()) { if (dimPatMatcher.groupCount() == 1) { parts.horiz = parts.vert = Integer.parseInt(dimPatMatcher.group(1)); } else if (dimPatMatcher.groupCount() == 2) { String horizStr = dimPatMatcher.group(1); parts.horiz = Integer.parseInt(horizStr); String vertStr = dimPatMatcher.group(2); if (vertStr != null) //weird that this check is needed... parts.vert = Integer.parseInt(vertStr); } else {//from ww w .j a v a 2 s . c o m throw new ParseException("Dimensions must adhere to regex " + regex); } } else { throw new ParseException("Dimensions must adhere to regex " + regex); } return parts; }
From source file:hoot.services.utils.PostgresUtils.java
static Map<String, String> parseTags(String tagsStr) { Map<String, String> tagsMap = new HashMap<>(); if ((tagsStr != null) && (!tagsStr.isEmpty())) { Pattern regex = Pattern.compile("(\"[^\"]*\")=>(\"(?:\\\\.|[^\"\\\\]+)*\"|[^,\"]*)"); Matcher regexMatcher = regex.matcher(tagsStr); while (regexMatcher.find()) { String key = regexMatcher.group(1); key = StringUtils.removeStart(key, "\""); key = StringUtils.removeEnd(key, "\""); String val = regexMatcher.group(2); val = StringUtils.removeStart(val, "\""); val = StringUtils.removeEnd(val, "\""); tagsMap.put(key, val); }// w ww.j a v a2s . c o m } return tagsMap; }
From source file:iox.refused.jhp.JHP_Parser.java
private static void compile(StringBuffer sb, String src) { Matcher m = TEXTLET.matcher(src); while (m.find()) { String name = BSLASHES.matcher(StringEscapeUtils.escapeJava(m.group(2))).replaceAll("\\\\\\\\"); m.appendReplacement(sb, "echo(\"" + name + "\");\n"); }/*from w ww . j a v a 2s.c om*/ m.appendTail(sb); }
From source file:Main.java
public static String cleanXmlNulls(String xml) { Pattern pattern = null;/*from w w w . java 2 s . com*/ Matcher matcher = null; pattern = Pattern.compile("[\\000]*"); matcher = pattern.matcher(xml); if (matcher.find()) { xml = matcher.replaceAll(""); } return xml; }