Example usage for java.util.regex Matcher find

List of usage examples for java.util.regex Matcher find

Introduction

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

Prototype

public boolean find() 

Source Link

Document

Attempts to find the next subsequence of the input sequence that matches the pattern.

Usage

From source file:Main.java

public static Boolean regex(String regex, String input) {
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(input);
    return matcher.find();
}

From source file:Main.java

private static int countWordOccurrences(String text, String word) {
    Matcher matcher = Pattern.compile(word).matcher(text);
    int count = 0;
    while (matcher.find()) {
        count++;//from  w  w  w  .  j  av  a2 s  . c o m
    }
    return count;
}

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 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:Main.java

public static ArrayList<String> getMatchString(String origin, String pattern, int groupId) {
    ArrayList<String> datas = new ArrayList<>();
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(origin);
    while (m.find()) {
        datas.add(m.group(groupId));/*from w  w w  .  j  ava 2 s . c  o  m*/
    }

    return datas;
}

From source file:Main.java

public static boolean checkEmail(String email) {
    String emailPattern = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";
    Pattern pattern = Pattern.compile(emailPattern);
    Matcher matcher = pattern.matcher(email);
    return matcher.find();
}

From source file:Main.java

public static boolean isLetter(String string) {
    String regExp = "^[a-zA-Z]*$";
    Pattern pattern = Pattern.compile(regExp);
    Matcher matcher = pattern.matcher(string);
    return matcher.find();// boolean
}

From source file:Main.java

public static String getFileName(String path) {
    Pattern pattern = Pattern.compile("[^\\" + File.separator + "]+.xml");
    Matcher matcher = pattern.matcher(path);
    if (matcher.find())
        return matcher.group().substring(0, matcher.group().length() - 4);
    return "";
}

From source file:Main.java

public static boolean isURL(String string) {
    String regExp = "^[\\w]*://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
    Pattern pattern = Pattern.compile(regExp);
    Matcher matcher = pattern.matcher(string);
    return matcher.find();// boolean
}

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();
}