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

/**
 * Helper method trimming the trimString pattern from the text input parameter
 * //from  w  w w  .j  ava2 s .  c  o m
 * @param trimString
 *            regex pattern
 * @param text
 *            text to be cleaned
 * @return the input text with any occurrences of the trimString pattern removed.
 */
private static String trimStringFromText(String trimString, String text) {
    if (trimString != EMPTY_STRING) {
        Pattern trimPattern = Pattern.compile(trimString);
        Matcher matcher = trimPattern.matcher(text);

        while (matcher.find()) {
            // System.out.println(matcher.group());
            text = text.replace(matcher.group(), EMPTY_STRING);
        }
    }
    return text;
}

From source file:Main.java

public static boolean possiblyWellformed(String in) {
    // extract starting element:
    in = in.trim();//from w  w w.java  2 s . c  o  m
    Matcher startMatcher = xmlStartPattern.matcher(in);
    if (startMatcher.find())
        return true;

    Matcher m = startingElementPattern.matcher(in);
    if (!m.matches())
        return false;
    String startingElementName = m.group(1);

    // check if fragment ends with the corresponding closing pattern:
    Pattern endPattern = Pattern.compile(".*</" + startingElementName + "\\s*>$");
    Matcher endMatcher = endPattern.matcher(in);

    return endMatcher.matches();
}

From source file:Main.java

static boolean isHostValid(String domain) {
    final Matcher contentMatcher = Pattern.compile(HOST_REGEX).matcher(domain);
    return contentMatcher.find();
}

From source file:Main.java

public static int computeAdditionalEmptySpacesLength(String text) {
    Matcher matcher = pattern.matcher(text);

    int len = 0;//from w ww . j a v a 2 s .c  o  m
    while (matcher.find()) {
        // encoded strings represent characters of length "1".
        // (TODO: need to check for any encoded string that represent a character with length more than 1) 
        len += (matcher.group(0).length() - 1);
    }
    return len;
}

From source file:Main.java

public static boolean isChinese(String name) {
    int j = 0;/*from ww w. ja v a 2  s.  c o m*/
    int i = name.length();
    Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]");
    Matcher m = pattern.matcher(name);
    while (m.find()) {
        j++;
    }
    if (i == j) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

private static String makeUrlHerf(String content) {
    if (content.trim().length() == 0) {
        return content;
    }/*  ww  w.  j a va 2 s .co m*/
    StringBuffer urlStringBuffer = new StringBuffer();

    Matcher matcherUrl = patternURL.matcher(content);
    while (matcherUrl.find()) {

        String url = matcherUrl.group();
        //            System.out.println("URL:" + url);
        String urlToHref = "<a href=\"" + url + "\">" + url + "</a>";
        matcherUrl.appendReplacement(urlStringBuffer, urlToHref);

    }
    matcherUrl.appendTail(urlStringBuffer);
    return urlStringBuffer.toString();
}

From source file:Main.java

public static boolean containsKey(String key) {
    boolean b = false;
    for (Entry<Pattern, Object> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(key);
        if (matcher.find()) {
            b = true;/*from   ww  w  .ja va 2 s  . c  o m*/
            break;
        }
    }

    return b;
}

From source file:Main.java

public static boolean isMatcherFinded(String patternStr, CharSequence input) {
    if (!isNullOrEmpty(patternStr) && null != input) {
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(input);
        if (null != matcher && matcher.find()) {
            return true;
        }/* ww  w .j  a va2  s  .com*/
    }

    return false;
}

From source file:Main.java

public static boolean containsKey(String key) {
    boolean b = false;
    for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(key);
        if (matcher.find()) {
            b = true;//from w w w .j a  v  a  2 s . c  o  m
            break;
        }
    }

    return b;
}

From source file:Main.java

public static String getConditionOfExpression(String expression) {
    // pattern for conditions
    Pattern conditionPattern = Pattern
            .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])(/[\\w\\W]+)?$");
    Matcher conditionMatcher = conditionPattern.matcher(expression);
    if (conditionMatcher.find() && (conditionMatcher.group().length() == expression.length())) {
        StringTokenizer st = new StringTokenizer(expression, "]");
        String condition = st.nextToken();
        condition = condition.substring(condition.indexOf("[") + 1);
        return condition;
    }/*from ww w  . ja v  a 2s  . c  o  m*/
    return null;
}