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 urlEncode(String str, String charset) throws UnsupportedEncodingException {
    Pattern p = Pattern.compile("[\u4e00-\u9fa5]+");
    Matcher m = p.matcher(str);
    StringBuffer b = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(b, URLEncoder.encode(m.group(0), charset));
    }/*from   w  ww.  j a v a  2  s . c om*/
    m.appendTail(b);
    return b.toString();
}

From source file:Main.java

public static CharSequence replace(Context ctx, String text) {
    if (text == null) {
        return null;
    }//from  w  ww.ja  v  a 2  s  .  c om
    SpannableString spannableString = new SpannableString(text);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        String key = factText.substring(1);
        if (emotionTexts.contains(factText)) {
            Bitmap bitmap = getDrawableByName(ctx, key);
            ImageSpan image = new ImageSpan(ctx, 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 format(String input, String... replacements) {
    String regex = ":[a-zA-Z]*";

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(input);

    Integer i = 0;//  w ww .  j  a  v  a2  s .c  om
    while (matcher.find()) {
        input = input.replace(matcher.group(), replacements[i]);
        i++;
    }

    System.out.println(input);

    return input;
}

From source file:Main.java

/**
 * Extract version number from objid./*from   w ww.  j a v  a 2 s  . c o m*/
 *
 * @param objid The objid.
 * @return The number of version or null.
 */
public static String getVersionNumberFromObjid(final CharSequence objid) {
    String version = null;
    final Matcher m = PATTERN_VERSION_NUMBER.matcher(objid);
    if (m.find()) {
        version = m.group(1);
    }
    return version;
}

From source file:Main.java

public static void findPattern(String regex, String source) {
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(source);

    System.out.println("Regex:" + regex);
    System.out.println("Text:" + source);
    while (m.find()) {
        System.out.println("Matched  Text:" + m.group() + ", Start:" + m.start() + ", " + "End:" + m.end());
    }//from w w  w  .  j  a va  2  s.  c om
}

From source file:Main.java

public static String matchCamelCase(String query, String str) {
    if (!query.matches("[A-Za-z\\*]+")) {
        return null;
    }/* w w w.  j a va  2  s  .com*/
    String head = "";
    int i;
    for (i = 0; i < query.length(); i++) {
        char charI = query.charAt(i);
        if (Character.isLowerCase(charI)) {
            head += charI;
        } else {
            break;
        }
    }
    if (i > 0) {
        head += "[^A-Z]*";
    }
    String tail = query.substring(i);
    String re = "\\b(";
    tail = tail.replaceAll("\\*", ".*?");
    re += head + tail.replaceAll("([A-Z][^A-Z]*)", "$1[^A-Z]*");
    re += ".*?)\\b";
    Pattern regex = Pattern.compile(re);
    Matcher m = regex.matcher(str);
    if (m.find()) {
        return m.group();
    } else {
        return null;
    }
}

From source file:Main.java

public static String encodeUrl(String url) {
    String new_url = url;
    Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(new_url);
    while (matcher.find()) {
        try {/* w ww  . j  a va2s  . c  o  m*/
            new_url = new_url.replaceAll(matcher.group(), URLEncoder.encode(matcher.group(), "gb2312"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return new_url;
}

From source file:Main.java

private static String parseContentDisposition(String paramString) {
    try {/*from www  .  j a  va2s  . co  m*/
        Matcher localMatcher = CONTENT_DISPOSITION_PATTERN.matcher(paramString);
        if (localMatcher.find()) {
            String str = localMatcher.group(1);
            return str;
        }
    } catch (IllegalStateException localIllegalStateException) {
    }
    return null;
}

From source file:cn.wanghaomiao.seimi.utils.StrFormatUtil.java

public static String parseCharset(String target) {
    Matcher matcher = charsetPattern.matcher(target);
    if (matcher.find()) {
        return matcher.group(1);
    }//from  w  w  w.  j  a v a  2 s  . c  om
    return "";
}

From source file:Main.java

public static String getPlainName(String qualifiedName) {
    Matcher matcher = PLAIN_NAME_START_PATTERN.matcher(qualifiedName);
    if (matcher.find()) {
        return qualifiedName.substring(matcher.start() + 1, qualifiedName.length());
    } else {//from   w  w  w . j  a  va  2  s. co  m
        return qualifiedName;
    }
}