List of usage examples for java.util.regex Pattern compile
public static Pattern compile(String regex)
From source file:Main.java
public static boolean isIDNumber(String strID) { Pattern pattern = Pattern.compile( "((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\\d{3}(x|X))|(\\d{4}))"); Matcher m = pattern.matcher(strID); if (m.matches()) { return true; } else {//from w ww. ja va 2s . c o m return false; } }
From source file:Main.java
public static boolean isInteger(String str) { Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); return pattern.matcher(str).matches(); }
From source file:Main.java
public static boolean checkPhone(String phone) { Pattern pattern = Pattern.compile("^(13[0-9]|15[0-9]|153|15[6-9]|180|18[23]|18[5-9])\\d{8}$"); Matcher matcher = pattern.matcher(phone); if (matcher.matches()) { return true; }/*from w w w. ja v a2s. co m*/ return false; }
From source file:Main.java
public static String filterHtml(String html) { Pattern pattern = Pattern.compile("<style[^>]*?>[\\D\\d]*?<\\/style>"); Matcher matcher = pattern.matcher(html); String htmlStr = matcher.replaceAll(""); pattern = Pattern.compile("<[^>]+>"); String filterStr = pattern.matcher(htmlStr).replaceAll(""); filterStr = filterStr.replace(" ", ""); filterStr = filterStr.replace(" ", ""); return filterStr.trim(); }
From source file:Main.java
public static Boolean checkCellPhone(String cellPhone) { Pattern pattern = Pattern.compile("^((13[0-9])|(15[0-9])|(18[0-9]))\\d{8}$"); Matcher matcher = pattern.matcher(cellPhone); return matcher.matches(); }
From source file:com.hp.avmon.trap.service.TrapService.java
public static void main(String[] args) { String text = "{3}123{3}{10}"; Pattern p = Pattern.compile(".*?(\\{.+?\\})"); Matcher m = p.matcher(text);/*from w ww. j a v a2 s . c o m*/ while (m.find()) { System.out.println(m.group(1)); } }
From source file:Main.java
public static boolean isPhoneNum(String phonenum) { Pattern pattern = Pattern.compile("^(1[0-9])\\d{9}$"); Matcher m = pattern.matcher(phonenum); if (m.matches()) { return true; } else {/* w w w .j a va 2 s . c o m*/ return false; } }
From source file:Main.java
public static String getModel(String useragent) { Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/"); Matcher matcher = pattern.matcher(useragent); String model = null;/* ww w . j a v a 2 s . c o m*/ if (matcher.find()) { model = matcher.group(1).trim(); } return model; }
From source file:Main.java
public static boolean regexIs(String str, String regex) { Pattern pattern = Pattern.compile(regex); Matcher isNum = pattern.matcher(str); return isNum.matches(); }
From source file:Main.java
public static boolean checkUserName(String username) { Pattern pattern = Pattern.compile("^[\\u4e00-\\u9fa5a-zA-Z][\\u4e00-\\u9fa5a-zA-Z0-9\\-]+$"); Matcher matcher = pattern.matcher(username); return matcher.find(); }