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:de.blizzy.documentr.system.Version.java

static Version fromString(String s) {
    Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); //$NON-NLS-1$

    s = s.replaceFirst("-.*$", StringUtils.EMPTY); //$NON-NLS-1$
    String[] parts = s.split("\\."); //$NON-NLS-1$
    return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
}

From source file:Main.java

public static boolean isHexAnd752Byte(String hexString, Context context) {
    if (hexString.matches("[0-9A-Fa-f]+") == false) {
        // Error, not hex.
        // Toast.makeText(context, R.string.info_not_hex_data,
        // Toast.LENGTH_LONG).show();
        return false;
    }//from  w ww.  j  a va  2 s . co  m
    if (hexString.length() != 1504) {
        // Error, not 752 byte (1504 chars).
        // Toast.makeText(context, R.string.info_not_16_byte,
        // Toast.LENGTH_LONG).show();
        return false;
    }
    return true;

}

From source file:Main.java

public static boolean isDateY(String str) {
    if (isEmpty(str))
        return false;
    return str.matches("^\\d{4}$");
}

From source file:Main.java

public static boolean isCharString(String str) {
    if (isEmpty(str))
        return false;
    return str.matches("[a-zA-Z0-9]*");
}

From source file:Main.java

public static boolean isActionPhone(String str) {
    if (isEmpty(str))
        return false;
    return str.matches("^1[0-9]{10}$");
}

From source file:Main.java

private static boolean elementIsRedundant(Element element) {
    if (element.hasAttributes())
        return false;
    if (!element.hasChildNodes())
        return true;
    NodeList children = element.getChildNodes();
    int childrenCount = children.getLength();
    for (int i = 0; i < childrenCount; ++i) {
        Node child = children.item(i);
        String value = child.getNodeValue();
        if (value != null && !value.matches("\\s*")) {
            return false; // Found non-whitespace text
        }//from   ww w . j a  v  a 2s  . co  m
    }
    return true;
}

From source file:Main.java

public static int chineseLength(String str) {
    int valueLength = 0;
    String chinese = "[\u0391-\uFFE5]";
    if (!isEmpty(str)) {
        for (int i = 0; i < str.length(); i++) {
            String temp = str.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 2;/*  ww w  . ja v a 2s  .co  m*/
            }
        }
    }
    return valueLength;
}

From source file:Main.java

private static String formatChannelNumber(String value) {

    if (null == value || "".equals(value)) {
        return null;
    }/*  w  w w .  jav  a 2s.c  om*/

    char delimiter = '_';
    for (char c : value.toCharArray()) {
        String test = String.valueOf(c);
        if (!test.matches("\\d")) {
            delimiter = c;
        }
    }

    value = value.replace(delimiter, '.');

    return value;
}

From source file:Main.java

/**
 * Check if a (hex) string is pure hex (0-9, A-F, a-f) and 16 byte (32 chars) long. If not show an error Toast in the context.
 * /*from w  w  w .j av a  2 s .c  o m*/
 * @param hexString The string to check.
 * @param context The Context in which the Toast will be shown.
 * @return True if sting is hex an 16 Bytes long, False otherwise.
 */
public static boolean isHexAnd16Byte(String hexString, Context context) {
    if (hexString.matches("[0-9A-Fa-f]+") == false) {
        // Error, not hex.
        // Toast.makeText(context, R.string.info_not_hex_data,
        // Toast.LENGTH_LONG).show();
        return false;
    }
    if (hexString.length() != 32) {
        // Error, not 16 byte (32 chars).
        // Toast.makeText(context, R.string.info_not_16_byte,
        // Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}

From source file:Main.java

public static int subStringLength(String str, int maxL) {
    int currentIndex = 0;
    int valueLength = 0;
    String chinese = "[\u0391-\uFFE5]";
    for (int i = 0; i < str.length(); i++) {
        String temp = str.substring(i, i + 1);
        if (temp.matches(chinese)) {
            valueLength += 2;/*  ww  w. j  a  v  a  2 s . co m*/
        } else {
            valueLength += 1;
        }
        if (valueLength >= maxL) {
            currentIndex = i;
            break;
        }
    }
    return currentIndex;
}