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 addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) {
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end()) {
                    spannable.removeSpan(span);
                } else {
                    set = false;/*from w w  w  .j  a  va  2 s .  com*/
                    break;
                }
            }
            if (set) {
                hasChanges = true;
                spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return hasChanges;
}

From source file:disko.ParagraphDetector.java

public static void detectParagraphs(String s, Collection<Ann> annotations) {
    Matcher m = paragraphSplitter.matcher(s);
    int start = 0;
    while (m.find()) {
        int end = m.start();
        String found = s.subSequence(start, end).toString();
        ParagraphAnn ann = new ParagraphAnn(start, end, found);
        annotations.add(ann);//from   w  w  w  .j a  va  2s  .  c  om
        log.debug("Found ParagraphAnn " + ann);
        start = m.end();
    }
    if (annotations.isEmpty() && s.trim().length() > 0)
        annotations.add(new ParagraphAnn(0, s.length(), s));
}

From source file:Main.java

/**
 * Converts the given xpath express to uppercase tags. All tags in IE are
 * returned as upper case and if the xpath isn't converted, no tags will match
 * the xpath.//from www .j  a va2 s.  com
 */
protected static String convertXPath(String xpath) {
    Matcher matcher = p.matcher(xpath);
    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
        String group = matcher.group();
        if (group.matches("\\/[\\w]*")) {
            buffer.append(group.toUpperCase());
        } else {
            buffer.append(group);
        }
    }
    return buffer.toString();
}

From source file:Main.java

private static int attemptMode() {
    String output = attemptCommand(new String[] { "mode", "con" });
    if (output == null) {
        return 80;
    }/*from www  .j  a  v a  2s  .  c  om*/

    Pattern pattern = Pattern.compile("Columns:[ \t]*(\\d+)");
    Matcher m = pattern.matcher(output);
    if (!m.find()) {
        return 80;
    }

    return Integer.parseInt(m.group(1));
}

From source file:Main.java

public static boolean isHTML(String s) {
    assert s != null : "Verify Null string";
    Pattern htmlPattern1 = Pattern.compile("<[a-zA-Z]+[0-9]*(\\s[a-zA-Z]+[0-9]*=.*)*\\s*/??>");
    Pattern htmlPattern2 = Pattern.compile("&#?[a-z0-9]+;");
    Matcher m1 = htmlPattern1.matcher(s);
    Matcher m2 = htmlPattern2.matcher(s);
    return m1.find() || m2.find();
}

From source file:com.github.terma.jenkins.githubprcoveragestatus.CoberturaParser.java

private static String findFirstOrNull(String string, String pattern) {
    Matcher matcher = Pattern.compile(pattern).matcher(string);
    if (matcher.find()) {
        return matcher.group(1);
    } else {//from   www  . j av a2  s  . c  o m
        return null;
    }
}

From source file:Main.java

public static String numberCheck(String num) {
    if (num == null || num.length() == 0) {
        return "";
    }//from   w w  w.j a  va 2s. c  o m
    Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)");
    Matcher matcher = pattern.matcher(num);
    StringBuffer bf = new StringBuffer(64);
    while (matcher.find()) {
        bf.append(matcher.group()).append(",");
    }
    int len = bf.length();
    if (len > 0) {
        bf.deleteCharAt(len - 1);
    }
    return bf.toString();
}

From source file:Main.java

private static String renderTelephone(String bodyHtml) {
    StringBuffer bodyStringBuffer = new StringBuffer();

    Matcher matcherTelContent = patternTagTitle.matcher(bodyHtml);
    while (matcherTelContent.find()) {

        String processContent = matcherTelContent.group(1);
        String htmlContent = matcherTelContent.group(2);
        if (htmlContent.equalsIgnoreCase("</script>") || htmlContent.equalsIgnoreCase("</a>")) {
            matcherTelContent.appendReplacement(bodyStringBuffer, processContent + htmlContent);
        } else {/*from  w ww.ja  v  a2 s . co m*/
            String telContentHasProcessed = makeTelNoHerf(processContent);
            matcherTelContent.appendReplacement(bodyStringBuffer, telContentHasProcessed + htmlContent);
        }
    }
    matcherTelContent.appendTail(bodyStringBuffer);
    return bodyStringBuffer.toString();
}

From source file:Main.java

public static List<String> matchingToList(String regex, String input, int group) {

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(input);
    List<String> groups = new ArrayList<String>();
    while (matcher.find()) {
        groups.add(matcher.group(group));
    }/*w w  w .j a  va  2s.c  o m*/
    return groups;
}

From source file:Main.java

public static String filterHtml(String str) {
    Pattern pattern = Pattern.compile(regxpForHtml);
    Matcher matcher = pattern.matcher(str);
    StringBuffer sb = new StringBuffer();
    boolean result1 = matcher.find();
    while (result1) {
        matcher.appendReplacement(sb, "");
        result1 = matcher.find();/*from  www.  j  av  a  2s . c  om*/
    }
    matcher.appendTail(sb);
    return sb.toString();
}