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 SpannableString StringToBitMap(Context context, String msg) {
    SpannableString ss = new SpannableString(msg);
    Pattern p = Pattern.compile("/mnt/sdcard/.+?\\.\\w{3}");
    Matcher m = p.matcher(msg);
    while (m.find()) {
        Bitmap bitmap = BitmapFactory.decodeFile(m.group());
        ImageSpan imageSpan = new ImageSpan(context, bitmap);
        ss.setSpan(imageSpan, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/* w  w  w .  j  a  v a2 s .co  m*/
    return ss;
}

From source file:Main.java

public static boolean checkString(String username) {

    Pattern pattern = Pattern.compile("^[a-zA-Z0-9]+$");
    Matcher matcher = pattern.matcher(username);
    return matcher.find();
}

From source file:Main.java

public static boolean hasChinese(String str) {
    if (TextUtils.isEmpty(str))
        return false;
    else {/*from ww w . j a  v  a2s .  com*/
        String regEx = "[\u4e00-\u9fa5]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        if (m.find())
            return true;
        else
            return false;
    }
}

From source file:Main.java

public static String getImgUrlFromHtml(String html) {
    String result = "";
    String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
    Pattern pattern = Pattern.compile(imgRegex);
    Matcher matcher = pattern.matcher(html);
    if (matcher.find()) {
        result = matcher.group(2);/*from  w  w  w  . j  av a 2 s  .c om*/
    }
    return result;
}

From source file:Main.java

public static boolean checkUserName(String username) {

    Pattern pattern = Pattern.compile("^[\\u4e00-\\u9fa5a-zA-Z][\\u4e00-\\u9fa5a-zA-Z0-9\\-]+$");
    Matcher matcher = pattern.matcher(username);
    return matcher.find();
}

From source file:Main.java

public static String findAppId(String storeLink) {
    Matcher matcher = PATTERN_ID.matcher(storeLink);
    return matcher.find() ? matcher.group() : "";
}

From source file:Main.java

public static String matchUrl(String text) {
    if (TextUtils.isEmpty(text)) {
        return null;
    }/* w  w w. j av  a 2s  . c  o  m*/
    Pattern p = Pattern.compile("[http]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]*", Pattern.CASE_INSENSITIVE);
    Matcher matcher = p.matcher(text);
    if (matcher.find()) {
        return matcher.group();
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * form file extention to lower case/*w w  w . jav  a2s.com*/
 * 
 * @param fileName
 * @return
 */
public static String lowerExtension(String fileName) {

    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(fileName);
    if (m.find()) {
        String extName = m.group().toLowerCase();
        fileName = fileName.replaceAll("(.[a-zA-Z0-9]+)$", extName);
    }

    return fileName;
}

From source file:Main.java

private static HashMap<String, String> parseContent(String src) {
    HashMap<String, String> map = new HashMap<String, String>();
    String patternStr = "http://(.*)\\?chat_id=[-]?(\\d+)&chat_name=(.+)";

    Pattern p = Pattern.compile(patternStr);
    Matcher m = p.matcher(src);
    if (!m.find()) {
        return null;
    } else if (m.groupCount() == 3) {
        map.put("chat_id", m.group(2));
        map.put("chat_name", m.group(3));
        return map;
    }//  w  ww . jav  a 2  s.  c o m

    return null;
}

From source file:Main.java

public static int getTypeOfTextDirection(String text) {
    Matcher matcher = RTL_CHAR.matcher(text);
    if (matcher.find()) {
        return View.TEXT_DIRECTION_RTL;
    } else {//from  w  w w. jav  a2  s .co  m
        return View.TEXT_DIRECTION_LTR;
    }
}