List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static String getEventOfExpression(String expression) { // pattern for events Pattern eventPattern = Pattern.compile("^[\\w\\W&&[^/\\[\\]]]+(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)?$"); Matcher eventMatcher = eventPattern.matcher(expression); if (eventMatcher.find() && (eventMatcher.group().length() == expression.length())) { StringTokenizer st = new StringTokenizer(expression, "[]/"); return st.nextToken(); }/*from www . java2s . c om*/ return null; }
From source file:Main.java
public static String getDateFromString(String content) { try {/*from ww w.j a v a 2 s . c o m*/ String strPattern = "DB_PoliceOfficeWork_(\\d{4}-\\d{2}-\\d{2}).db"; Pattern pattern = Pattern.compile(strPattern); Matcher matcher = pattern.matcher(content); while (matcher.find()) { return matcher.group(1); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
From source file:Main.java
public static String extractTitle(String html) { if (html == null) { return null; }/*from ww w. java2 s . c om*/ Matcher matcher = patternTitle.matcher(html); if (matcher.find()) { String title = matcher.group(1); if (title != null) { title = title.trim(); } return title; } return null; }
From source file:Main.java
public static List<String> getImageUrls(String content) { List<String> result = new ArrayList<String>(); Pattern pattern = Pattern.compile(REGEX_MATCH_IMAGE, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(1); if (group != null) { result.add(group);// w w w . ja va2s . com } } return result; }
From source file:Main.java
/** * Regex matcher for PART X pattern in multi-part videos * http://txt2re.com/index-java.php3/* www .j a v a 2s. c o m*/ * * @param token * @return */ @SuppressLint("DefaultLocale") private static boolean isMultiPartSeries(String token) { String re1 = "(PART)"; // Word 1 String re2 = "( )"; // White Space 1 String re3 = "(\\d+)"; // Integer Number 1 Pattern p = Pattern.compile(re1 + re2 + re3, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(token.toUpperCase()); return m.find(); }
From source file:Main.java
public static ArrayList<String> retrieveLinks(String text) { ArrayList<String> links = new ArrayList<String>(); String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(text); while (m.find()) { String urlStr = m.group(); if (urlStr.startsWith("(") && urlStr.endsWith(")")) { char[] stringArray = urlStr.toCharArray(); char[] newArray = new char[stringArray.length - 2]; System.arraycopy(stringArray, 1, newArray, 0, stringArray.length - 2); urlStr = new String(newArray); System.out.println("Finally Url =" + newArray.toString()); }//from w w w . java 2 s . co m System.out.println("...Url..." + urlStr); links.add(urlStr); } return links; }
From source file:Main.java
public static int getRedId(String string) { for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(string); while (matcher.find()) { return entry.getValue(); }//from w w w.j a v a2s .c o m } return -1; }
From source file:Main.java
public static boolean containsKey(String key) { boolean b = false; for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(key); if (matcher.find()) { b = true;//from w w w . j a va2s.c o m break; } } return b; }
From source file:Main.java
/** * Extract namespaces into a map for adding to the builder. * E.g. xmlns:xsd="http://www.w3.org/2001/XMLSchema" * @param xml XML source//from w w w . ja va 2s . c o m * @return map of namespaces : URL, e.g. [ "xsd" : "http://www.w3.org/2001/XMLSchema" ] */ private static Map<String, String> parseNamespaces(String xml) { Map<String, String> nsMap = new HashMap<String, String>(); Pattern nsPat = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); Matcher nsMat = nsPat.matcher(xml); while (nsMat.find()) { String ns = nsMat.group(1); String url = nsMat.group(2); nsMap.put(ns, url); } return nsMap; }
From source file:Main.java
public static Long parseLong(String value) { if (value == null) { return 0L; }/*from www .jav a2s . com*/ Long val = 0L; try { Matcher matcher = pattern.matcher(value); if (matcher.find()) { String num = matcher.group(0); val = Long.parseLong(num); } } catch (Exception e) { e.printStackTrace(); } return val; }