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 isHanZi(String string) {
    String regExp = "^[\u4e00-\u9fa5]*$";
    Pattern pattern = Pattern.compile(regExp);
    Matcher matcher = pattern.matcher(string);
    return matcher.find();// boolean
}

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;
    }/* w  w  w. ja v a2s .  c  om*/
    return true;
}

From source file:Main.java

public static int getCharacterPosition(String string, int next, String sub) {
    Matcher slashMatcher = Pattern.compile(sub).matcher(string);
    int index = 0;
    while (slashMatcher.find()) {
        index++;//from  w w  w. j  av  a 2 s  .  co  m
        if (index == next)
            break;
    }
    return slashMatcher.start();
}

From source file:Main.java

public static boolean checkName(String name) {
    String str = "^([\\w]|[\\u4e00-\\u9fa5])+";
    Pattern p = Pattern.compile(str);
    Matcher m = p.matcher(name);//from  ww  w .j a  va2s .  c om
    return m.matches();
}

From source file:Main.java

public static boolean isAMail(String mail) {
    if (mail == null)
        return false;
    Pattern p = Pattern.compile("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@");
    Matcher m = p.matcher(mail);/*from  w w w.  ja v a  2s  .com*/
    return m.matches();
}

From source file:Main.java

public static boolean isIdCard(String string) {
    String regExp = "\\d{17}[[0-9],0-9xX]";
    Pattern pattern = Pattern.compile(regExp);
    Matcher matcher = pattern.matcher(string);
    return matcher.find();// boolean
}

From source file:MatcherResetCharSequenceExample.java

public static void test() {
    String output = "";
    Pattern p = Pattern.compile("\\d");
    Matcher m1 = p.matcher("01234");

    while (m1.find()) {
        System.out.println("\t\t" + m1.group());
    }/*from ww  w .  j a  va 2 s  .c om*/
    //now reset the matcher with new data
    m1.reset("56789");
    System.out.println("After resetting the Matcher");
    //iterate through the matcher
    while (m1.find()) {
        System.out.println("\t\t" + m1.group());
    }
}

From source file:Main.java

public static boolean validatestr(String str) {
    Pattern pattern = Pattern.compile("[0-9],.");
    Matcher matcher = pattern.matcher(str);

    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);//w  w w . j  a va  2s  .  com
    if (m.find()) {
        return true;
    }
    return false;
}

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