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:com.xpeppers.phonedirectory.validator.PhoneDirectoryValidator.java

private static void validatePhoneNumberFormat(String phoneNumber, ValidationResponse validationResponse) {
    if (!validationResponse.hasErrors() && !phoneNumber.matches(REGEX)) {
        validationResponse.setStatus(ValidationStatus.FAIL);
        validationResponse.getErrorMessages()
                .add(new ErrorMessage("phoneNumber", "Incorrect format for Phone number. "
                        + "Format must be: +39 02 1234567, but has been find: " + phoneNumber));
    }/*from ww w  .  jav a 2s .c o m*/
}

From source file:Main.java

public static boolean isDate(String str) {
    if (isEmpty(str))
        return false;
    //      return str.matches("^\\d{4}(-|.|/)\\d{2}(-|.|/)\\d{2}$");
    return str.matches("^\\d{4}(-)\\d{2}(-)\\d{2}$");
}

From source file:com.esofthead.mycollab.core.utils.StringUtils.java

/**
 * Check whether <code>text</code> is an Ascii string
 *
 * @param text/*  ww  w .ja  v  a2 s  .c o  m*/
 * @return
 */
public static boolean isAsciiString(String text) {
    return text.matches("\\A\\p{ASCII}*\\z");
}

From source file:net.easymfne.factionsdb.Util.java

/**
 * Calculate the number of milliseconds represented by a time String.
 * /*from   ww  w . ja v  a2 s.  c o  m*/
 * @param timeString
 *            String representing a time
 * @return Number of milliseconds
 * @throws TimeFormatException
 */
public static long calculateMillis(String timeString) throws TimeFormatException {
    if (timeString.matches("^[0-9.]+[sS]$")) {
        return (long) (SECOND * getTimeDouble(timeString));
    } else if (timeString.matches("^[0-9.]+[mM]")) {
        return (long) (MINUTE * getTimeDouble(timeString));
    } else if (timeString.matches("^[0-9.]+[hH]")) {
        return (long) (HOUR * getTimeDouble(timeString));
    } else if (timeString.matches("^[0-9.]+[dD]")) {
        return (long) (DAY * getTimeDouble(timeString));
    } else {
        throw new TimeFormatException(timeString);
    }
}

From source file:Main.java

private static boolean isAnException(String string) {
    for (String ex : AN_EXCEPTIONS) {
        if (string.matches("^" + ex + ".*")) {
            // if (string.equalsIgnoreCase(ex)) {
            return true;
        }// ww w .  j  ava  2  s .com
    }

    return false;
}

From source file:Main.java

/**
 * Method to split the path components of a file into a List
 * @param f the file to split/*from   w  ww . ja  v a  2 s . c om*/
 * @return a new list containing the components of the path as strings
 */
protected static List<String> splitPath(File f) {
    List<String> result;
    File parent = f.getParentFile();
    if (parent == null) {
        result = new ArrayList<String>();
        if (f.getName().length() > 0) {
            // We're at the root but have a name so we have a relative path
            // for which we need to add the first component to the list
            result.add(f.getName());
        } else if (IS_WINDOWS) {
            String strF = f.toString();
            if (strF.matches(WINDOWS_DRIVE_ROOT_REGEX)) {
                // We're on windows and the path is <Drive>:\ so we
                // add the <Drive>: to the list
                result.add(strF.substring(0, strF.length() - 1).toUpperCase());
            }
        }
    } else {
        result = splitPath(parent);
        result.add(f.getName());
    }
    return result;
}

From source file:Main.java

public static String formatFingerprint(String fingerprint) {
    if (TextUtils.isEmpty(fingerprint) || fingerprint.length() != 64 // SHA-256 is 64 hex chars
            || fingerprint.matches(".*[^0-9a-fA-F].*")) // its a hex string
        return "BAD FINGERPRINT";
    String displayFP = fingerprint.substring(0, 2);
    for (int i = 2; i < fingerprint.length(); i = i + 2)
        displayFP += " " + fingerprint.substring(i, i + 2);
    return displayFP;
}

From source file:Main.java

public static boolean isMobileNO(String mobiles) {

    String telRegex = "[1][358]\\d{9}";
    if (TextUtils.isEmpty(mobiles))
        return false;
    else//w ww. j a  v  a 2  s  . co m
        return mobiles.matches(telRegex);
}

From source file:com.akrema.stringeval.utils.ExprUtils.java

/**
 * extract arguments from the input string
 * and specify if we have integer or string arguments
 *
 * @param inputstring the parameters in the expression
 * @return map contain number of argument+value
 *//* w  w  w  .ja  va  2s.  co m*/
public static HashMap<Integer, Object> extractArguments(String inputstring) throws InputStringException {
    HashMap<Integer, Object> args = new HashMap<Integer, Object>();

    StrTokenizer tokenizer = new StrTokenizer(inputstring, StringCONST.DELM);
    if (tokenizer.size() > 3) {
        throw new InputStringException(" the arguments list must be 3 ");
    }
    int index = 1;
    while (tokenizer.hasNext()) {
        String ch = tokenizer.nextToken();
        if (ch.matches("\\d+")) {
            args.put(index, Integer.parseInt(ch));
            index++;
        } else {
            args.put(index, ch);
            index++;
        }

    }

    return args;
}

From source file:Main.java

public static Map parseIni(String s) {
    Object obj;/*from w  w  w. ja  v  a  2s  .  c  om*/
    if (s == null || s.length() <= 0) {
        obj = null;
    } else {
        obj = new HashMap();
        String as[] = s.split("\n");
        int i = as.length;
        int j = 0;
        while (j < i) {
            String s1 = as[j];
            if (s1 != null && s1.length() > 0) {
                String as1[] = s1.trim().split("=", 2);
                if (as1 != null && as1.length >= 2) {
                    String s2 = as1[0];
                    String s3 = as1[1];
                    if (s2 != null && s2.length() > 0 && s2.matches("^[a-zA-Z0-9_]*"))
                        ((Map) (obj)).put(s2, s3);
                }
            }
            j++;
        }
    }
    return ((Map) (obj));
}