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 String replaceBlank(String str) {
    if (str == null) {
        return null;
    }//from   w  ww .  j av  a2  s.  co m
    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
    Matcher m = p.matcher(str);
    String after = m.replaceAll("");
    return after;
}

From source file:Main.java

public static boolean isNumber(String number) {
    boolean flag = false;
    try {//  w  ww .j  av a  2  s  .  c om
        Pattern p = Pattern.compile("[0-9]+");
        Matcher m = p.matcher(number);
        flag = m.matches();
    } catch (Exception e) {
        flag = false;
    }
    return flag;
}

From source file:Main.java

public static boolean isData(String number) {
    Pattern pattern = Pattern.compile("^[0-9]*$");
    Matcher m = pattern.matcher(number);
    if (m.matches()) {
        return true;
    } else {/* w w w  .j  a va  2 s .  c om*/
        return false;
    }
}

From source file:Main.java

public static boolean isEmailValid(String email) {
    if (isEmpty(email)) {
        return false;
    }//from  w  w  w . ja  v  a 2 s  .  c o  m
    String regex = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
    Pattern p = Pattern.compile(regex);
    Matcher matcher = p.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static String replaceSymbol(String str) {
    String dest = "";
    if (str != null) {
        // Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }/*w w w. j av  a  2  s.c om*/
    return dest;
}

From source file:Main.java

public static boolean isContainsChinese(String str) {
    String regEx = "[\u4e00-\u9fa5]";
    Pattern pat = Pattern.compile(regEx);
    Matcher matcher = pat.matcher(str);
    boolean flg = false;
    if (matcher.find()) {
        flg = true;//from ww  w .j a v a2 s .  c o  m
    }
    return flg;
}

From source file:Main.java

public static boolean isMobileNO(String mobiles) {
    if (mobiles == null) {
        return false;
    }//from w ww.jav a 2s.  c  om
    // Pattern p =
    // Pattern.compile("^((1[0-9][0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
    Pattern p = Pattern.compile("^(1)\\d{10}$");
    Matcher m = p.matcher(mobiles);
    return m.matches();
}

From source file:Main.java

public static boolean isDouble(String str) {
    Pattern p = Pattern.compile("^\\d+(\\.\\d+)?$");
    Matcher m = p.matcher(str);
    if (m.matches()) {
        return true;
    }/*from   w  w  w.  j  a  v a 2  s .c om*/
    return false;
}

From source file:Main.java

public static boolean isPasswordValid(String password) {
    if (isEmpty(password)) {
        return false;
    }/*  w w  w  .  j  a va 2  s .  com*/
    String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$";
    Pattern p = Pattern.compile(regex);
    Matcher matcher = p.matcher(password);
    return matcher.matches();
}

From source file:Main.java

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