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

/**
 * Check how much times the string matches the regex
 * @param str//  w  w  w  .j a v a  2s.  c  o  m
 * @param regex
 * @return
 */
public static int getMatchedStringCount(String str, String regex) {
    int ret = 0;

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(str);
    while (matcher.find()) {
        ret++;
    }

    return ret;
}

From source file:Main.java

public static boolean parseOptionalBooleanAttr(String line, Pattern pattern) {
    Matcher matcher = pattern.matcher(line);
    if (matcher.find()) {
        return BOOLEAN_YES.equals(matcher.group(1));
    }/*ww  w  . jav  a 2  s  .  c  o m*/
    return false;
}

From source file:Main.java

public static String parseOptionalStringAttr(String paramString, Pattern paramPattern) {
    Matcher localMatcher = paramPattern.matcher(paramString);
    if ((localMatcher.find()) && (localMatcher.groupCount() == 1))
        return localMatcher.group(1);
    return null;//from  ww  w.j a  v a 2s .  c  o m
}

From source file:Main.java

public static boolean find(String checkStr, String regex) {
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(checkStr);

    return matcher.find();
}

From source file:Main.java

public static String splitDate(String pattern, String url) {
    String date = "";
    Matcher m = Pattern.compile(pattern).matcher(url);

    if (m.find()) {
        date = m.group(1);/*from w w  w  .j  a  v a2s  . c o  m*/
    }

    return date;
}

From source file:Main.java

public static ArrayList<String> getResultUrl(String html) {
    ArrayList<String> resultUrl = new ArrayList<String>();
    String re = "<h3 class=\\\\\"r\\\\\"(.+?)>(.+?)<a href=\\\\\"(.+?)\\\\\" target=\\\\\"_blank\\\\\">(.+?)<\\\\/a>";
    System.out.println(re);//from  w w  w .  java  2  s  . c  o  m
    Pattern pattern = Pattern.compile(re);
    Matcher matcher = pattern.matcher(html);
    while (matcher.find()) {
        resultUrl.add(matcher.group(3).replace("\\/", "/").replace("&amp;", "&").replace("&amp;", "&"));
        System.out.println(matcher.group(3).replace("\\/", "/").replace("&amp;", "&").replace("&amp;", "&"));

    }

    return resultUrl;
}

From source file:Main.java

public static String extract(String response, Pattern p) {
    Matcher matcher = p.matcher(response);
    if (matcher.find() && matcher.groupCount() >= 1) {
        try {/*from www . j  a va  2 s  .  co  m*/
            return URLDecoder.decode(matcher.group(1), UTF_8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    throw new RuntimeException(
            "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null);

}

From source file:Main.java

public static ArrayList<String> getResultContent(String html) {
    ArrayList<String> resultContent = new ArrayList<String>();
    String re = "<div class=\"sort_name_detail\"><a href=\"(.+?)\" target=\"_blank\" title=\"(.+?)\">";
    Pattern pattern = Pattern.compile(re);
    Matcher matcher = pattern.matcher(html);
    while (matcher.find()) {
        resultContent.add(matcher.group(2).replace("\n", "").replace(" ", "").replace("\t", "")
                .replace("<b>", "").replace("</b>", ""));
        System.out.println(matcher.group(2));

    }/*from   ww  w.  ja v  a2  s .  c o  m*/

    return resultContent;
}

From source file:Main.java

public static boolean hasPathVariables(String routePath) {
    Matcher matcher = PATH_VARIABLE_PATTERN.matcher(routePath);
    return matcher.find();
}

From source file:Main.java

public static boolean isEmailAddress(String emailAddress) {
    if (!TextUtils.isEmpty(emailAddress)) {
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$");
        Matcher matcher = pattern.matcher(emailAddress);
        return matcher.find();
    }//from ww  w  .  j ava  2s  . co m
    return false;
}