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 isTel(String tel) {
    Pattern p = Pattern.compile("^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$");
    Matcher m = p.matcher(tel);/*  www. j a  v  a2  s . c  o m*/
    return m.matches();
}

From source file:Main.java

public static boolean isPhone(String str) {
    Pattern p = Pattern.compile("^((14[0-9])|(13[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$");
    Matcher m = p.matcher(str);//from   w  w  w.j  av  a  2 s  .  co m
    return m.matches();
}

From source file:Main.java

public static boolean isName(String str) {
    Pattern p = Pattern.compile("^[\\u4E00-\\u9FFF]+$");
    Matcher matcher = p.matcher(str);
    return matcher.matches();
}

From source file:Main.java

public static boolean hasNumber(String x) {
    // .replaceAll("\\\\","")
    Pattern p = Pattern.compile("[0-9]");
    return p.matcher(x).find();
}

From source file:Main.java

public static boolean isTel(String tel) {
    Pattern p = Pattern.compile("^((\\d{7,8})|(0\\d{2,3}-\\d{7,8})|(1[34578]\\d{9}))$");
    Matcher m = p.matcher(tel);/* w ww  . java2s  .c o  m*/
    return m.matches();
}

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);//from   w  w  w .j a v  a  2  s.  c o  m
    return m.matches();
}

From source file:Main.java

public static boolean isOToN(String number) {
    Pattern p = Pattern.compile("\\d");
    Matcher m = p.matcher(number);
    return m.matches();
}

From source file:Main.java

public static String subString(String sub) {
    Pattern pp = Pattern.compile("\\s*|\t|\r|\n");
    Matcher mm = pp.matcher(sub);
    return mm.replaceAll("");
}

From source file:Main.java

public static boolean checkQQ(String QQ) {
    String regex = "[1-9]\\d{4,14}";
    return Pattern.compile(regex).matcher(QQ).matches();
}

From source file:MatcherPatternExample.java

public static void test() {
    Pattern p = Pattern.compile("\\d");
    Matcher m1 = p.matcher("55");
    Matcher m2 = p.matcher("fdshfdgdfh");

    System.out.println(m1.pattern() == m2.pattern());
}