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 patternCode(String patternCoder, String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return false;
    }//from w w  w. j a v a 2s  . c  o  m
    Pattern p = Pattern.compile(patternCoder);
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static List<String> matcherList(String regx, String content, int groupIndex) {
    List<String> ls = new ArrayList<String>();
    Pattern pattern = Pattern.compile(regx, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(content);
    while (matcher.find()) {
        ls.add(matcher.group(groupIndex));
    }/*w w  w.  j  a va2  s  . c  o m*/
    return ls;
}

From source file:Main.java

public static String patternCode(String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return null;
    }/* w w  w  .j  a  v a  2  s. co  m*/
    Pattern p = Pattern.compile("(?<!\\d)\\d{6}(?!\\d)");
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:Main.java

public static boolean isContainSpecialChar(String str, String charSet) {

    Pattern patt = Pattern.compile(charSet);
    Matcher matcher = patt.matcher(str);
    return matcher.find();
}

From source file:Main.java

/**
 * Match a pattern with a single capturing group and return the content of
 * the capturing group//from  w w w .j  av  a2s  .  c  o m
 *
 * @param text    the text to match against
 * @param pattern the pattern (regular expression) must contain one and only one
 *                capturing group
 * @return
 */
public static String matchPattern(String text, String pattern) {
    // Use regular expression matching to pull the min and max values from
    // the output of gdalinfo
    Pattern p1 = Pattern.compile(pattern, Pattern.MULTILINE);
    Matcher m1 = p1.matcher(text);
    if (m1.find()) {
        if (m1.groupCount() == 1) {
            return m1.group(1);
        } else {
            throw new RuntimeException("error matching pattern " + pattern);
        }
    } else {
        throw new RuntimeException("error matching pattern " + pattern);
    }
}

From source file:Main.java

/**
 * @param value/*from w ww.j av a  2s. c  o m*/
 * @param regEx
 * @return
 */
public static boolean validateAgainstRegEx(String value, String regEx) {
    Pattern pattern = Pattern.compile(regEx);
    if (null != value) {
        Matcher matcher = pattern.matcher(value);
        return matcher.find();
    }
    return false;
}

From source file:Main.java

public static String getNoTagsTrimText(String xml) {
    Matcher m = tagPattern.matcher(xml);
    if (!m.find()) {
        return xml;
    }//from   w w w.  ja  v a  2 s . c o m
    String replaced = m.replaceAll("");

    replaced = replaced.replaceAll("\\r\\n", "");
    replaced = replaced.replaceAll("\\n", "");
    replaced = replaced.replaceAll("\\t", "");

    replaced = replaced.replaceAll("\\s+", " ");
    replaced = replaced.trim();

    return replaced;
}

From source file:Main.java

public static String getYoutubeIdFormUrl(String url) {
    String pattern = "(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*";

    Pattern compiledPattern = Pattern.compile(pattern);
    Matcher matcher = compiledPattern.matcher(url);

    if (matcher.find()) {
        return matcher.group();
    }// ww w.  j  av  a2s  .c o m
    return "";
}

From source file:Main.java

public static ArrayList<String> getResultUrl(String html) {
    ArrayList<String> resultUrl = 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()) {
        resultUrl.add(matcher.group(1));
        System.out.println(matcher.group(1));

    }// www  .j  a  v a  2 s  .  co m

    return resultUrl;
}

From source file:Main.java

public static String getZipFromFixphone(String strNumber) {
    Matcher matcher = PATTERN_ZIPCODE.matcher(strNumber);
    if (matcher.find()) {
        return matcher.group(1);
    }//w ww  . jav  a2s .c o  m

    return "";
}