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:MatchNameFormats.java

public static boolean isNameValid(String name) {
    boolean retval = false;
    String nameToken = "\\p{Upper}(\\p{Lower}+\\s?)";
    String namePattern = "(" + nameToken + "){2,3}";
    retval = name.matches(namePattern);

    String msg = "NO MATCH: pattern:" + name + "\r\n           regex :" + namePattern;

    if (retval) {
        msg = "MATCH     pattern:" + name + "\r\n           regex :" + namePattern;
    }//from  w  ww .j  a v  a 2 s .  c  o m

    System.out.println(msg + "\r\n");
    return retval;
}

From source file:Main.java

public static boolean isNumOrWord(String str) {
    String regularExpression = "[a-z0-9A-Z]*";

    if (isEmpty(str)) {
        return false;
    } else if (!str.matches(regularExpression)) {
        return false;
    }/*from  w  w w  . ja  va 2s.  c  o m*/
    return true;
}

From source file:Main.java

public static boolean isEmailAddress(String value) {
    try {/*  w  ww.ja  v a2 s .  c  om*/
        if (value == null)
            return false;
        value = value.trim();
        if (!value.matches("^[_0-9a-z-][_.0-9a-z/-]+@([0-9a-z][_0-9a-z.-]+.)+[a-z]{2,3}$")) {
            return false;
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:de.jfachwert.pruefung.NumberValidator.java

private static Locale guessLocale(String value) {
    return value.matches("\\d+(\\.\\d{3})*(,\\d+)?") ? Locale.GERMAN : Locale.ENGLISH;
}

From source file:Main.java

/**
 * Check whether this string starts with a number that needs "an" (e.g.
 * "an 18% increase")// w  w  w.java  2 s . com
 * 
 * @param string
 *            the string
 * @return <code>true</code> if this string starts with 11, 18, or 8,
 *         excluding strings that start with 180 or 110
 */
public static boolean requiresAn(String string) {
    boolean req = false;

    String lowercaseInput = string.toLowerCase();

    if (lowercaseInput.matches(AN_AGREEMENT) && !isAnException(lowercaseInput)) {
        req = true;

    } else {
        String numPref = getNumericPrefix(lowercaseInput);

        if (numPref != null && numPref.length() > 0 && numPref.matches("^(8|11|18).*$")) {
            Integer num = Integer.parseInt(numPref);
            req = checkNum(num);
        }
    }

    return req;
}

From source file:me.fromgate.messagecommander.PLListener.java

private static String textToString(String message) {
    String text = message;
    if (text.matches("^\\{\"text\":\".*\"\\}")) {
        text = text.replaceAll("^\\{\"text\":\"", "");
        text = text.replaceAll("\"\\}$", "");
    }//from  w w  w  . j  a va2 s. co m
    return ChatColor.stripColor(text);
}

From source file:Main.java

public static boolean isColor(String s) {
    final String alpha = "[0-9a-fA-F]";
    final String color = "#" + alpha + "{6}";
    if (s.matches(color))
        return true;
    return false;
}

From source file:Main.java

public static int[] parseIntegerList(String list, int minValue, int maxValue) {
    ArrayList tmpList = new ArrayList();
    Pattern p = Pattern.compile("(\\d*)-(\\d*)");
    String[] a = list.replace(',', ' ').split("\\s+");
    int i = a.length;

    for (int i$ = 0; i$ < i; ++i$) {
        String token = a[i$];

        try {/*from w  ww .  jav  a  2 s .c om*/
            if (token.matches("\\d+")) {
                tmpList.add(Integer.valueOf(Integer.parseInt(token)));
            } else {
                Matcher e = p.matcher(token);

                if (e.matches()) {
                    String a1 = e.group(1);
                    String b = e.group(2);
                    int min = a1.equals("") ? minValue : Integer.parseInt(a1);
                    int max = b.equals("") ? maxValue : Integer.parseInt(b);

                    for (int i1 = min; i1 <= max; ++i1) {
                        tmpList.add(Integer.valueOf(i1));
                    }
                }
            }
        } catch (NumberFormatException var15) {
            ;
        }
    }

    if (minValue <= maxValue) {
        int var16 = 0;

        while (var16 < tmpList.size()) {
            if (((Integer) tmpList.get(var16)).intValue() >= minValue
                    && ((Integer) tmpList.get(var16)).intValue() <= maxValue) {
                ++var16;
            } else {
                tmpList.remove(var16);
            }
        }
    }

    int[] var17 = new int[tmpList.size()];

    for (i = 0; i < var17.length; ++i) {
        var17[i] = ((Integer) tmpList.get(i)).intValue();
    }

    return var17;
}

From source file:Main.java

public static boolean isEmail(String email) {
    if (email == null)
        email = "";
    String regex = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
    return email.matches(regex);
}

From source file:Main.java

/**
 * Validate email string//from  w  w  w  . j ava2s  .  c  o m
 * @param email is object of String
 * @return true if valid email otherwise false
 */
public static boolean isEmail(String email) {
    String pattern = "^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\\.([a-zA-Z]){2,4}";
    return email != null && email.trim().length() > 0 && email.matches(pattern);
}