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:com.cy.driver.common.util.ValidateUtil.java

/**
 * ?//from  ww  w . ja va2s . c  o  m
 * @param str
 * @return
 */
public static boolean isNumberic(String str) {
    Pattern pattern = Pattern.compile("^\\d*$");
    return pattern.matcher(str).matches();
}

From source file:Main.java

public static String url2Folder(String url) {
    Pattern p = Pattern.compile("android/(.*?)/");
    Matcher m = p.matcher(url);
    if (m.find()) {
        MatchResult mr = m.toMatchResult();
        return mr.group(1);
    } else {//from  w ww  . j  a v  a  2 s  .  c  o m
        return null;
    }
}

From source file:Main.java

public static boolean isPhoneNumber(String phoneNumber) {
    if (TextUtils.isEmpty(phoneNumber)) {
        return false;
    }/*from www . ja va2  s. c  o  m*/
    String reg = "^[0-9]{11}$";
    Pattern pattern = Pattern.compile(reg);
    Matcher matcher = pattern.matcher(phoneNumber);
    return matcher.matches();
}

From source file:Main.java

/**
 * form file extention to lower case/*  w  ww . j  ava  2  s .  c  o m*/
 * 
 * @param fileName
 * @return
 */
public static String lowerExtension(String fileName) {

    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(fileName);
    if (m.find()) {
        String extName = m.group().toLowerCase();
        fileName = fileName.replaceAll("(.[a-zA-Z0-9]+)$", extName);
    }

    return fileName;
}

From source file:Main.java

public static boolean isUrlCorrect(String url) {
    if (url != null) {
        String check = "(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(url);
        return matcher.matches();
    }//  w  ww.j a v  a 2  s. c  o  m
    return false;
}

From source file:Main.java

public static boolean checkIDCard(String idCard) {
    Pattern p = Pattern.compile("^(\\d{15}|\\d{17}[\\dxX])$");
    Matcher m = p.matcher(idCard);
    return m.matches();
}

From source file:Main.java

public static boolean validateEmail(String email) {
    Pattern pattern = Pattern.compile(PATTERN_EMAIL);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static boolean isNumeric(String str) {
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);
    if (isNum.matches()) {
        return true;
    } else {//from  w  w w.ja  va  2s .c  o  m
        return false;
    }
}

From source file:Main.java

public static boolean checkPhoneNumber(String phoneNumber) {
    if (TextUtils.isEmpty(phoneNumber)) {
        return false;
    }/*from   w w  w.  j  a  v a2 s  .com*/
    String reg = "^[0-9]{11}$";
    Pattern pattern = Pattern.compile(reg);
    Matcher matcher = pattern.matcher(phoneNumber);
    return matcher.matches();
}

From source file:Main.java

public static boolean isContainChinese(String txt) {
    Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]");
    Matcher m = p.matcher(txt);
    if (m.find()) {
        return true;
    }/*from  ww w .  j  a va  2 s  .  c  o  m*/
    return false;
}