List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static String getIdInUrl(String type, String url) { Pattern p = Pattern.compile("/" + type + "/(\\w+)(\\?|/)*"); Matcher matcher = p.matcher(url); if (matcher.find()) { return matcher.group(1); }/* ww w .j a v a2s . c o m*/ return ""; }
From source file:Main.java
/** * check if string is a url//from w w w . j av a 2 s.co m * use regular expressionn ^http(s)?:\/\/(.*?) */ public static Boolean hasUrlFormat(String str) { Boolean isUrl = false; Pattern p = Pattern.compile("^http(s)?:\\/\\/(.*?)"); Matcher m = p.matcher(str); if (m.find()) isUrl = true; return isUrl; }
From source file:Main.java
public static boolean isNumeric(String str) { String regEx = "^-?[0-9]+$"; Pattern pat = Pattern.compile(regEx); Matcher mat = pat.matcher(str); if (mat.find()) { return true; } else {//from ww w. jav a 2s .c om return false; } }
From source file:Main.java
public static boolean isPassword(String pwdString) { String regEx = "[~!@#$%^&*<>]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(pwdString); if (m.find()) { return false; }/* ww w.j a va2 s .co m*/ return true; }
From source file:Main.java
public static String u2s(String u) { Pattern pat = Pattern.compile("[\\\\U|\\\\u]([0-9a-fA-F]{4})"); Matcher mat = pat.matcher(u); while (mat.find()) { String HEX = mat.group(1); char v = (char) (Integer.parseInt(HEX.toUpperCase(), 16)); mat = pat.matcher(u = u.replace("\\" + mat.group(), "" + v)); }//from w w w . ja v a 2 s .c o m return u; }
From source file:Main.java
public static boolean checkChineseString(String str) { boolean isChinese = false; String regEx = "[\\u4e00-\\u9fa5]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); while (m.find()) { isChinese = true;// www. j ava2s. c o m break; } return isChinese; }
From source file:Main.java
private static String extractPattern(String string, String pattern, int group) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(string); if (m.find()) { return m.group(group); } else {//from w w w.ja v a 2 s .co m return null; } }
From source file:Main.java
public static boolean isChineseChar(String str) { boolean temp = false; if (str.matches("[\u4e00-\u9fa5]+")) { return true; }//from w w w.j a va2 s . c om Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); Matcher m = p.matcher(str); if (m.find()) { temp = true; } return temp; }
From source file:Main.java
public static List getHtmlTagContent(String html, String tagname) { List resultList = new ArrayList(); Pattern p = Pattern.compile("<" + tagname + ">([^</" + tagname + ">]*)"); Matcher m = p.matcher(html); while (m.find()) { resultList.add(m.group(1));/* www .j a va 2 s. c o m*/ } return resultList; }
From source file:Main.java
public static String getStringDigits(String text) { text = null == text ? "" : text; StringBuilder digitList = new StringBuilder(""); Pattern p = Pattern.compile("(\\d+)"); Matcher m = p.matcher(text); while (m.find()) { String find = m.group(1).toString(); digitList.append(find);/*ww w .j av a 2 s .com*/ } return digitList.toString(); }