List of usage examples for java.util.regex Pattern matcher
public Matcher matcher(CharSequence input)
From source file:Main.java
public static String getEnglishNums(String num) { Pattern p = Pattern.compile("(?<=\\d)(?=(\\d\\d\\d)+$)"); Matcher m = p.matcher(num); return m.replaceAll(","); }
From source file:Main.java
public static long parseDuration(String icalDuration) { final int GROUP_SECONDS = 1; final String PATTERN = "-?P(\\d)+S"; long durationInSeconds = -1; Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(icalDuration); if (m.groupCount() > 1) { durationInSeconds = Long.parseLong(m.group(GROUP_SECONDS)); }/*w w w . j a v a 2 s .com*/ return durationInSeconds; }
From source file:Main.java
public static String getClassNameFromTableName(String tableName) { Pattern p = Pattern.compile("(_+|^)(\\w?)"); Matcher m = p.matcher(tableName); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, m.group(2).toUpperCase()); }//from ww w . jav a2 s . co m m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static boolean checkEmailIsOK(String emailStr) { Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); Matcher m = p.matcher(emailStr); return m.matches(); }
From source file:Main.java
public static boolean checkPhoneNumber(String phoneNumber) { Pattern pattern = Pattern.compile("^1[0-9]{10}$"); Matcher matcher = pattern.matcher(phoneNumber); return matcher.matches(); }
From source file:Main.java
public static boolean isEmail(String str) { String check = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; Pattern regex = Pattern.compile(check); Matcher matcher = regex.matcher(str); if (matcher.matches()) { return true; } else {// w ww . j a v a 2s .co m return false; } }
From source file:Main.java
public static boolean isEmail(String str) { Pattern p1 = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); Matcher m = p1.matcher(str); return m.matches(); }
From source file:Main.java
public static boolean isContainChinese(String str) { Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); Matcher m = p.matcher(str); if (m.find()) { return true; }//from w ww. j a v a 2s . co m return false; }
From source file:Main.java
public static String getAttributeNameFromColName(String tableName) { Pattern p = Pattern.compile("_+(\\w?)"); Matcher m = p.matcher(tableName); StringBuffer sb = new StringBuffer(); while (m.find()) { if (m.start() != 0) m.appendReplacement(sb, m.group(1).toUpperCase()); else//from w w w .j a v a 2 s . c om m.appendReplacement(sb, m.group(1).toLowerCase()); } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static String getVerifyCodeFromSms(String smsBody) { Pattern pattern = Pattern.compile("\\d{6}"); Matcher matcher = pattern.matcher(smsBody); if (matcher.find()) { return matcher.group(); }/*from w ww.j av a2 s . c o m*/ return null; }