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: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());
    }//  w ww. j  a v  a2s  . com
    //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 int extractInt(String str) {
    Matcher matcher = Pattern.compile("\\d+").matcher(str);

    if (!matcher.find())
        throw new NumberFormatException("For input string [" + str + "]");

    return Integer.parseInt(matcher.group());
}

From source file:Main.java

private static void match(String REGEX, String INPUT) {
    Pattern p = Pattern.compile(REGEX);
    Matcher m = p.matcher(INPUT);
    int count = 0;

    while (m.find()) {
        count++;// ww  w. ja  va2  s.  c  om
        System.out.println("\nMatch number: " + count);
        System.out.println("start() : " + m.start());
        System.out.println("end()   : " + m.end());
        System.out.println("group() : " + m.group());
    }
}

From source file:Main.java

public static String getParameterFromUrl(String param, String url) {
    Pattern p = Pattern.compile(param + "=([^&]+)");
    Matcher m = p.matcher(url);
    m.find();
    return m.group(1);
}

From source file:Main.java

public static boolean isSpecialChar(String str) {
    Pattern p = Pattern.compile("[!*'\"();:@&=+$,/?%#%]");
    Matcher m = p.matcher(str);
    return m.find();
}

From source file:Main.java

private static boolean match(String pattern, String str) {
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(str);
    return m.find();
}

From source file:Main.java

public static boolean isChinese(String str) {
    String regEx = "[\\u4e00-\\u9fa5]+";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.find();
}

From source file:Main.java

static boolean hasDoubleByteCharacters(String text) {
    //        Pattern p = Pattern.compile("[^[a-z][A-Z][0-9][.;'\":!]");
    Pattern p = Pattern.compile("[^p{Alnum}p{Punct}]");
    Matcher m = p.matcher(text);
    return m.find();
}

From source file:Main.java

public static boolean checkEmail(String email) {
    Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    Matcher m = p.matcher(email);
    return m.find();
}

From source file:Main.java

public static boolean isEmail(String email) {
    String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(email);
    return m.find();
}