Example usage for java.util.regex Pattern compile

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

Introduction

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

Prototype

public static Pattern compile(String regex) 

Source Link

Document

Compiles the given regular expression into a pattern.

Usage

From source file:Main.java

public static boolean passwordRegExp_8(String password) {
    Pattern p = Pattern.compile("^(?![A-Z]*$)(?![a-z]*$)(?![0-9]*$)(?![^a-zA-Z0-9]*$)\\S{8,}");
    Matcher m = p.matcher(password);
    return m.matches();
}

From source file:Main.java

public static boolean checkEmail(String email) {
    Pattern pattern = Pattern.compile(
            "^([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})(\\]?)$");
    Matcher matcher = pattern.matcher(email);
    return matcher.find();
}

From source file:Main.java

private static boolean match(String pattern, String str) {
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(str);/*  w  ww. j  av a  2s . c  o m*/
    return m.find();
}

From source file:Main.java

public static String removeCommas(String text) {
    Pattern p = Pattern.compile("(\\d+),(\\d\\d\\d$|\\d\\d\\d\\D)");
    String oldText;//  w  w  w .j  ava2  s.c o  m
    do {
        oldText = text;
        Matcher m = p.matcher(text);
        text = m.replaceAll("$1$2");
    } while (oldText.equalsIgnoreCase(text) == false);
    return text;
}

From source file:Main.java

public static boolean isCorrect(String rgx, String res) {
    Pattern p = Pattern.compile(rgx);

    Matcher m = p.matcher(res);/*w w  w.  j a va 2  s. co m*/

    return m.matches();
}

From source file:Main.java

public static boolean isMatchPassword(String str) {
    Pattern pattern = Pattern.compile("[a-zA-Z0-9]{6,16}");
    Matcher isNum = pattern.matcher(str);
    return isNum.matches();
}

From source file:Main.java

public static boolean isNumeric(String str) {
    Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
    return pattern.matcher(str).matches();
}

From source file:Main.java

public static boolean isMobilePhone(String phone) {
    Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[6-8])|(18[0-9]))\\d{8}$");
    Matcher matcher = pattern.matcher(phone);
    return matcher.matches();
}

From source file:Main.java

public static boolean checkEmail(String email) {

    Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$");
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static boolean isValidMobile(String mobiles) {
    Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");

    Matcher m = p.matcher(mobiles);

    return m.matches();

}