Example usage for java.util.regex Matcher matches

List of usage examples for java.util.regex Matcher matches

Introduction

In this page you can find the example usage for java.util.regex Matcher matches.

Prototype

public boolean matches() 

Source Link

Document

Attempts to match the entire region against the pattern.

Usage

From source file:Main.java

public static boolean isLong(String str) {
    if ("0".equals(str.trim())) {
        return true;
    }/*w  w  w  . j a va  2 s .  co m*/
    Pattern pattern = Pattern.compile("^[^0]\\d*");
    Matcher isNum = pattern.matcher(str);
    if (!isNum.matches()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean possiblyWellformed(String in) {
    // extract starting element:
    in = in.trim();/*from   www .  j  a va 2 s.  c  om*/
    Matcher startMatcher = xmlStartPattern.matcher(in);
    if (startMatcher.find())
        return true;

    Matcher m = startingElementPattern.matcher(in);
    if (!m.matches())
        return false;
    String startingElementName = m.group(1);

    // check if fragment ends with the corresponding closing pattern:
    Pattern endPattern = Pattern.compile(".*</" + startingElementName + "\\s*>$");
    Matcher endMatcher = endPattern.matcher(in);

    return endMatcher.matches();
}

From source file:Main.java

public static boolean isFloat(String str) {
    if (isLong(str)) {
        return true;
    }/*w  w w  .  j a v a 2 s . c  o m*/
    Pattern pattern = Pattern.compile("\\d*\\.{1}\\d+");
    Matcher isNum = pattern.matcher(str);
    if (!isNum.matches()) {
        return false;
    }
    return true;
}

From source file:Utils.java

private static List<File> getFilesRecurse(File dir, Pattern pattern, File exclude, boolean rec,
        List<File> fileList) {
    for (File file : dir.listFiles()) {
        if (file.equals(exclude)) {
            continue;
        }//  w  ww . ja  va  2s.com
        if (file.isDirectory() && rec) {
            getFilesRecurse(file, pattern, exclude, rec, fileList);
        } else {
            Matcher m = pattern.matcher(file.getName());
            if (m.matches()) {
                fileList.add(file);
            }
        }
    }
    return fileList;
}

From source file:Main.java

public static int verifyUsername(@NonNull String username) {

    int length = countLength(username);

    if (length < 4 || length > 20) {
        return VERIFY_LENGTH_ERROR;
    }//from w  w w. j a  va2 s .  c o  m

    String regex = "^[a-zA-Z0-9\u4E00-\u9FA5]+$";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(username);

    if (!matcher.matches())
        return VERIFY_TYPE_ERROR;
    return VERIFY_SUCCESS;
}

From source file:Main.java

public static boolean checkIP(String value) {
    Pattern pattern = Pattern
            .compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
                    + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
    Matcher matcher = pattern.matcher(value);
    boolean IPcheck = matcher.matches();

    if (IPcheck)/*from  ww w  .  j  a v a  2  s. com*/
        return true;

    return false;
}

From source file:Main.java

public static boolean checkEmailAddress(String emailString) {
    String regEx = "\\w+([-+._]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";

    Matcher matcherObj = Pattern.compile(regEx).matcher(emailString);

    if (matcherObj.matches()) {
        return true;
    } else {//from   w ww.java  2 s  .  c  om
        return false;
    }
}

From source file:Main.java

public static boolean checkPwd(int type, String name) {

    String regEx = "";

    switch (type) {
    case 0://w ww . j ava2 s  .com
        regEx = "^[A-Za-z0-9_]{6,20}$";
        break;
    case 1:
        regEx = "^[\\u4E00-\\u9FA5A-Za-z]+$";
        break;
    case 2:
        regEx = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$";
        break;
    case 3:
        regEx = "^[\\u2E80-\\u9FFF]+$";
        break;
    case 4:
        regEx = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
        break;
    default:
        break;
    }

    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(name);
    return m.matches();
}

From source file:Main.java

/**
 * Converts percentage string into actual based on a relative number
 *
 * @param percentage percentage string/*from   www .  j  a va 2  s . c om*/
 * @param relative   relative number
 * @param offset     offset number
 * @return actual float based on relative number
 */

static float fromPercentageToFloat(String percentage, float relative, float offset, float scale) {
    Matcher matched = percentageRegExp.matcher(percentage);
    if (matched.matches()) {
        return Float.valueOf(matched.group(1)) / 100 * relative + offset;
    } else {
        return Float.valueOf(percentage) * scale + offset;
    }
}

From source file:Main.java

/**
 * Creates a map of tag name to clean header XML by running a substitution
 * regex on each entry of tag to dirty header XML.
 *
 * @param dirtyXmlMap a map of tag name to dirty header XML
 * @return a map of tag name to clean header XML
 *//*from   ww w .ja  v  a 2s. c o  m*/
private static Map<String, String> createTagToCleanXmlMap(Map<String, String> dirtyXmlMap) {
    Map<String, String> cleanXmlMap = new HashMap<String, String>();
    for (Entry<String, String> sensitiveXml : dirtyXmlMap.entrySet()) {
        Pattern p = Pattern.compile(
                String.format(SENSITIVE_REGEX, sensitiveXml.getKey(), sensitiveXml.getKey()),
                Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher m = p.matcher(sensitiveXml.getValue());
        if (m.matches()) {
            cleanXmlMap.put(sensitiveXml.getKey(), m.replaceFirst("$1******$2"));
        }
    }
    return cleanXmlMap;
}