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 Object dontShowPasswords(Object aReturnValue, Method aMethod) {
    Object result = aReturnValue;
    Matcher matcher = PASSWORD_PATTERN.matcher(aMethod.getName());
    if (matcher.find()) {
        result = HIDDEN_PASSWORD_VALUE;//from  w  w  w .j a  va  2  s  .c  om
    }
    return result;
}

From source file:Main.java

/**
 * 01061234567 010-61234567 13611111111 400-400-4000
 *
 * @param phoneNumStr phoneNum//from  ww w.  j  a  v a2 s .  co  m
 * @return boolean
 */
public static boolean isPhoneNumber(String phoneNumStr) {
    if (phoneNumStr == null || phoneNumStr.trim().length() == 0) {
        return false;
    }
    Matcher matcherTelNo = patternTelNo.matcher(phoneNumStr);
    return matcherTelNo.find();
}

From source file:Main.java

public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern,
        Drawable drawable) {//from   www. ja va  2 s  .co  m
    SpannableString ss = charSequence instanceof SpannableString ? (SpannableString) charSequence
            : new SpannableString(charSequence);
    try {
        ImageSpan is = new ImageSpan(drawable);
        Pattern pattern = Pattern.compile(regPattern);
        Matcher matcher = pattern.matcher(ss);
        while (matcher.find()) {
            String key = matcher.group();
            ss.setSpan(is, matcher.start(), matcher.start() + key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    } catch (Exception ex) {
    }

    return ss;
}

From source file:Main.java

public static boolean containsEncodedText(String text) {
    Matcher matcher = pattern.matcher(text);
    int count = 0;
    while (matcher.find()) {
        count++;//from w  ww .  j  a v a  2  s .  co  m
    }
    return count > 0;
}

From source file:Main.java

public static String html2Text(String html) {
    StringBuffer filterText = new StringBuffer();

    Pattern p = Pattern.compile("<([^>]*)>");
    Matcher m = p.matcher(html);
    while (m.find()) {
        m.appendReplacement(filterText, "");
    }/*from  ww  w  .  j  a  va 2  s. co  m*/
    m.appendTail(filterText);

    return unescapeHTML(filterText.toString());
}

From source file:Main.java

public static Document stringToDocument(final String source) {
    String tmp = source.trim();//from  ww w  .j  av  a  2  s .  co m
    if (!tmp.startsWith("<?xml")) {
        tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + tmp;
    }
    String encode = "utf-8";
    Pattern p = Pattern.compile("<?.*encoding=\"([^ ]*)\".*?>");
    Matcher m = p.matcher(tmp);
    if (m.find()) {
        encode = m.group(1);
    }
    try {
        return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(tmp.getBytes(encode)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isContainsChinese(String str) {
    String regEx = "[\u4e00-\u9fa5]";
    Pattern pat = Pattern.compile(regEx);
    Matcher matcher = pat.matcher(str);
    boolean flg = false;
    if (matcher.find()) {
        flg = true;/*from w w  w .ja v  a 2 s . c  o m*/
    }
    return flg;
}

From source file:Main.java

public static CharSequence htmlfrom(CharSequence text) {
    Pattern htmlflag1 = Pattern.compile("<(.*?)>");
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    Matcher matcher = htmlflag1.matcher(text);
    while (matcher.find()) {
        builder.delete(matcher.start(), matcher.end());
        text = builder;/*from  www.j  a  v a2  s . c  o m*/
        matcher = htmlflag1.matcher(text);
    }
    Pattern htmlflag2 = Pattern.compile("&(.*?);");
    matcher = htmlflag2.matcher(text);
    while (matcher.find()) {
        builder.delete(matcher.start(), matcher.end());
        text = builder;
        matcher = htmlflag2.matcher(text);
    }

    return builder.toString();

}

From source file:musiccrawler.validate.Validator.java

public static boolean isValidUrl(String url) {
    if (StringUtils.isNotBlank(url)) {
        Pattern pattern = Pattern.compile(Constant.URL_VALID_PATTERN);
        Matcher matcher = pattern.matcher(url);
        return matcher.find();
    }/*w  w w.ja  v a  2  s.c  o  m*/
    return false;
}

From source file:Main.java

public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern,
        Drawable drawable) {// www. ja  v a  2 s  .c  o m
    SpannableString ss = charSequence instanceof SpannableString ? (SpannableString) charSequence
            : new SpannableString(charSequence);
    try {
        ImageSpan is = new ImageSpan(drawable);
        Pattern pattern = Pattern.compile(regPattern);
        Matcher matcher = pattern.matcher(ss);
        while (matcher.find()) {
            String key = matcher.group();
            ss.setSpan(is, matcher.start(), matcher.start() + key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    } catch (Exception ex) {
        // Logger.e(TAG, ex);
    }

    return ss;
}