Example usage for java.util.regex Pattern matcher

List of usage examples for java.util.regex Pattern matcher

Introduction

In this page you can find the example usage for java.util.regex Pattern matcher.

Prototype

public Matcher matcher(CharSequence input) 

Source Link

Document

Creates a matcher that will match the given input against this pattern.

Usage

From source file:Main.java

public static boolean isID(String s) {
    String strPattern = "^\\d{15}|^\\d{17}([0-9]|X|x)$";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(s);
    return m.matches();
}

From source file:Main.java

public static boolean ifHasOnlyStr(String str) {
    String strPattern = "[a-zA-Z\u4e00-\u9fa5]+$";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(str);
    return m.matches();
}

From source file:Main.java

public static boolean checkPassword(String pwd) {
    String strPattern = "[A-Za-z0-9]{6,12}";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(pwd);
    return m.matches();
}

From source file:Main.java

public static boolean existZH(String str) {
    String regEx = "[\\u4e00-\\u9fa5]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    while (m.find()) {
        return true;
    }//from w  w  w . j a  v a 2s .c o  m
    return false;
}

From source file:Main.java

public static String extract(String response, Pattern p) {
    Matcher matcher = p.matcher(response);
    if (matcher.find() && matcher.groupCount() >= 1) {
        try {/*from   w ww.ja  v  a  2  s. com*/
            return URLDecoder.decode(matcher.group(1), UTF_8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    throw new RuntimeException(
            "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null);

}

From source file:Main.java

public static boolean isEmail(String email) {
    // String//from w  w  w  . j a  v a2 s  .  c  o m
    // str="^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
    // String
    // str="^([a-z0-9A-Z]+[-|//.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?//.)+[a-zA-Z]{2,}$";
    String str = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    Pattern p = Pattern.compile(str);
    Matcher m = p.matcher(email);
    return m.matches();
}

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;
    }/*from   w  w  w.  j a v a2  s.  c  o  m*/
    return true;
}

From source file:Main.java

public static boolean isDandelionNo(String dandelionNo) {
    Pattern p = Pattern.compile(ACC_REGULAR);
    Matcher m = p.matcher(dandelionNo);
    return m.matches();
}

From source file:Main.java

public static String parseOptionalStringAttr(String line, Pattern pattern) {
    Matcher matcher = pattern.matcher(line);
    if (matcher.find()) {
        return matcher.group(1);
    }//from www  . j  a v a2  s .  c  o m
    return null;
}

From source file:Main.java

public static String parseOptionalStringAttr(String line, Pattern pattern) {
    Matcher matcher = pattern.matcher(line);
    if (matcher.find() && matcher.groupCount() == 1) {
        return matcher.group(1);
    }/* w  ww .j  a v a2  s . c o  m*/
    return null;
}