List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
/** * Extracts a desired string given a string and a pattern using regex * /*from ww w . ja v a2 s . c om*/ * @param response the string to extract from * @param pattern the regex pattern used to extract * * @return desired extracted string */ @SuppressWarnings("deprecation") public static String extract(String response, Pattern pattern) { String extraction = null; Matcher matcher = pattern.matcher(response); if (matcher.find() && matcher.groupCount() >= 1) { extraction = URLDecoder.decode(matcher.group(1)); } return extraction; }
From source file:Main.java
public static boolean isTempFile(String fileName) { Matcher result = pattern.matcher(fileName); return result.find(); }
From source file:cu.uci.uengine.utils.RegexUtils.java
public static int getDataSetNumber(File file) throws InvalidDataSetNameException { String baseName = FilenameUtils.getBaseName(file.getName()); Pattern p = Pattern.compile("\\d+$");//Digits at string end. Matcher m = p.matcher(baseName); if (!m.find()) { throw new InvalidDataSetNameException(String.format("DataSet %s is not a valid name.", baseName)); }/* ww w .ja v a 2s . c o m*/ int dataSetNumber = Integer.parseInt(m.group()); return dataSetNumber; }
From source file:Main.java
public static List<String> matcher(String reg, String text) { List<String> matches = new ArrayList<String>(); Matcher m = Pattern.compile(reg).matcher(text); if (m.find()) { if (m.groupCount() > 0) { for (int i = 1; i <= m.groupCount(); i++) { matches.add(m.group(i)); }// w w w. ja v a2 s. c o m } } return matches; }
From source file:Main.java
private static String getFileName(HttpURLConnection conn) { String fileName = conn.getHeaderField("Content-Disposition"); Matcher matcher = REGEX_FILE_NAME.matcher(fileName); if (matcher.find()) { return matcher.group(1); } else {// ww w. j a va 2s . c om return null; } }
From source file:Main.java
public static boolean validate(String emailStr) { Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr); return matcher.find(); }
From source file:Main.java
public static String getHost(String url) { if (url == null || "".equals(url.trim())) return null; Pattern p = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+"); Matcher matcher = p.matcher(url); if (matcher.find()) return matcher.group(); else/*from w w w.ja v a2 s. c o m*/ return null; }
From source file:Main.java
public static String getOneStrFromString(String strPattern, String content) { try {/*from w ww . j a va2 s.c om*/ 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 boolean checkEmailValid(String email) { if ((email == null) || (email.trim().length() == 0)) { return false; }//from w w w . j av a 2s. c o m String regEx = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(email.trim().toLowerCase()); return m.find(); }
From source file:com.plan.proyecto.servicios.utilidades.UrlParser.java
public static List<String> pullLinks(String text) { List<String> links = new ArrayList(); 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(")")) { urlStr = urlStr.substring(1, urlStr.length() - 1); }//from ww w . j a v a2 s . c o m links.add(urlStr); } return links; }