Example usage for java.lang String matches

List of usage examples for java.lang String matches

Introduction

In this page you can find the example usage for java.lang String matches.

Prototype

public boolean matches(String regex) 

Source Link

Document

Tells whether or not this string matches the given regular expression.

Usage

From source file:Main.java

public static String getFirst(String pinyin) {
    if (pinyin == null || pinyin.length() < 1) {
        return SHARP;
    }/*w  w w.  ja  v a  2  s  . c  om*/
    String fistLetter = pinyin.substring(0, 1);
    if (!fistLetter.matches(PATTERN)) {
        return SHARP;
    }
    return fistLetter;
}

From source file:Main.java

private static boolean isAlphaNumeric(String s) {
    String pattern = "^[a-zA-Z0-9]*$";
    if (s.matches(pattern)) {
        return true;
    }//from  ww  w  .j  a v  a 2  s.  c om
    return false;
}

From source file:Main.java

public static Date string2Date(String yyyyMMdd) {
    if (null != yyyyMMdd && yyyyMMdd.matches("^\\d{8}$")) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        try {/*from   www .j a v a2s  .c om*/
            return format.parse(yyyyMMdd);
        } catch (ParseException e) {
            return new Date();
        }
    }

    return new Date();
}

From source file:Main.java

public static boolean isBankCard(String cardId) {
    String regx = "\\d{16}|\\d{19}";
    return cardId.matches(regx);
}

From source file:Main.java

public static boolean renameFile(File file, String newFileName) {
    if (newFileName.matches(FILENAME_REGIX)) {
        File newFile = null;//from w w  w  .  j a  va 2 s.co  m
        if (file.isDirectory()) {
            newFile = new File(file.getParentFile(), newFileName);
        } else {
            String temp = newFileName + file.getName().substring(file.getName().lastIndexOf('.'));
            newFile = new File(file.getParentFile(), temp);
        }
        if (file.renameTo(newFile)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isValid_name(String str) {
    String regex = "[\u4E00-\u9FA5]{2,5}";
    return str.matches(regex);
}

From source file:Main.java

private static boolean isImageLink(String content) {
    return content.matches("(http(s?):/)(/[^/]+)+" + "\\.(?:jpg|gif|png)");
    //        return content.replaceAll("(http(s?):/)(/[^/]+)+" + "\\.(?:jpg|gif|png)", "[img]$0[/img]");
}

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.// ww w.j  ava  2  s .  co m
 */
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

public static boolean isValidMobiNumber(String paramString) {
    String regex = "^1\\d{10}$";
    if (paramString.matches(regex)) {
        return true;
    }//from ww  w  .  ja  va2 s . co m
    return false;
}

From source file:Main.java

public static boolean isChineseChar(String str) {
    boolean temp = false;
    if (str.matches("[\u4e00-\u9fa5]+")) {
        return true;
    }/* w  ww .j av  a 2 s .  c  o  m*/
    Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
    Matcher m = p.matcher(str);
    if (m.find()) {
        temp = true;
    }
    return temp;
}