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

private static String capitalizeTagNames(String xpath) {
    Matcher m = TAG_PATTERN.matcher(xpath);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String text = m.group();/*  w w  w.j a  v a 2s  . c  om*/
        m.appendReplacement(sb, Matcher.quoteReplacement(text.toUpperCase()));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

public static boolean contain(String text) {
    boolean isContain = false;
    if (TextUtils.isEmpty(text)) {
        return false;
    }//from   w ww .  j  a v  a 2 s .  c  om
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        if (contain(emojiCodes, factText)) {
            isContain = true;
            break;
        }
    }
    return isContain;
}

From source file:Main.java

private static int[] getIndex(String text, String regex) {
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(text);
    int[] data = new int[2];
    // Check all occurrences
    while (matcher.find()) {
        data[0] = matcher.start();//from   w w  w .ja v a  2  s. c  o  m
        data[1] = matcher.end();
        //            System.out.print("Start index: " + matcher.start());
        //            System.out.print(" End index: " + matcher.end());
        //            System.out.println(" Found: " + matcher.group());
    }
    return data;
}

From source file:org.jspringbot.keyword.expression.engine.function.StaticMethodUtils.java

public static Method getMethod(Class clazz, String methodSignature) {
    Matcher matcher = METHOD_SIGNATURE_PATTERN.matcher(methodSignature);

    if (matcher.find()) {
        String methodName = matcher.group(2);
        String parameterTypes = matcher.group(3);

        List<Class> types = new ArrayList<Class>();
        for (String parameterType : StringUtils.split(parameterTypes, ',')) {
            ClassEditor editor = new ClassEditor();
            editor.setAsText(parameterType);
            types.add((Class) editor.getValue());
        }// ww w.j av a 2s . co  m

        return MethodUtils.getAccessibleMethod(clazz, methodName, types.toArray(new Class[types.size()]));
    }

    throw new IllegalStateException(String.format("Invalid method signature '%s' found.", methodSignature));
}

From source file:com.gistlabs.mechanize.document.html.JsoupDataUtil.java

/**
 * Parse out a charset from a content type header.
 * @param header e.g. "text/html; charset=EUC-JP"
 * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased.
 *///ww  w.java  2s .c om
public static String getCharsetFromContentType(Header header) {
    if (header == null || header.getValue() == null || "".equals(header.getValue()))
        return null;
    Matcher m = charsetPattern.matcher(header.getValue());
    if (m.find()) {
        return m.group(1).trim().toUpperCase();
    }
    return null;
}

From source file:Main.java

public static CharSequence replace(Context context, String text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    }/*from w  w w. j a v  a  2 s.  co  m*/
    SpannableString spannableString = new SpannableString(text);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        String key = factText.substring(1, factText.length() - 1);
        if (contain(emojiCodes, factText)) {
            Bitmap bitmap = getEmojiDrawable(context, key);
            ImageSpan image = new ImageSpan(context, bitmap);
            int start = matcher.start();
            int end = matcher.end();
            spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}

From source file:Main.java

public static String checkMobileNum(String phoneNum) {
    if (TextUtils.isEmpty(phoneNum))
        return "";

    Pattern p1 = Pattern.compile("^((\\+{0,1}86){0,1})1[0-9]{10}");
    Matcher m1 = p1.matcher(phoneNum);
    if (m1.matches()) {
        Pattern p2 = Pattern.compile("^((\\+{0,1}86){0,1})");
        Matcher m2 = p2.matcher(phoneNum);
        StringBuffer sb = new StringBuffer();
        while (m2.find()) {
            m2.appendReplacement(sb, "");
        }/*from   w ww.  j  ava2 s.c o  m*/
        m2.appendTail(sb);
        return sb.toString();
    } else {
        return phoneNum;
    }
}

From source file:com.sap.prd.mobile.ios.mios.XCodeVersionUtil.java

public static String getBuildVersion(String xCodeVersionString) throws XCodeException {
    Pattern buildPattern = Pattern.compile("Build version (\\w+)", Pattern.CASE_INSENSITIVE);
    Matcher buildMatcher = buildPattern.matcher(xCodeVersionString);
    if (buildMatcher.find()) {
        return buildMatcher.group(1);
    }//from  w  ww .j a v a 2 s  . c om
    throw new XCodeException("Could not get xcodebuild build version");
}

From source file:Main.java

@NonNull
public static int[] getStartEnd(@Nullable String s) {
    if (TextUtils.isEmpty(s)) {
        return new int[] { -1, -1 };
    }//from  w ww  . j av a  2 s  .  c o  m
    Matcher first = Pattern.compile(timeDuringPattern).matcher(s);
    if (first.find()) {
        String sS = first.group();
        if (!TextUtils.isEmpty(sS)) {
            int start = Integer.parseInt(first.group());
            Matcher last = Pattern.compile(lastNumberPattern).matcher(s);
            int end = start;
            if (last.find()) {
                String eS = last.group();
                if (!TextUtils.isEmpty(eS)) {
                    end = Integer.parseInt(eS);
                }
            }
            return new int[] { start, end };
        } else {
            return new int[] { -1, -1 };
        }
    } else {
        return new int[] { -1, -1 };
    }
}

From source file:com.omertron.themoviedbapi.model.comparator.PersonCreditDateComparator.java

/**
 * locate a 4 digit year in a date string
 *
 * @param date/*w w w.j av a 2s .c o m*/
 * @return
 */
private static int extractYear(String date) {
    int year = 0;
    Matcher m = YEAR_PATTERN.matcher(date);
    if (m.find()) {
        year = Integer.parseInt(m.group(1));
    }

    // Give up and return 0
    return year;
}