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.akrema.stringeval.utils.ExprUtils.java

/**
 * check if a string is a digit or not//from  ww w  . ja va  2  s . c  om
 *
 * @param str passed string
 * @return True if the str match the pattern
 */
public static boolean isNumeric(String str) {
    return str.matches("-?\\d+(\\.\\d+)?");
}

From source file:Main.java

public static boolean isValidEmailAddress(String inputString) {
    String emailAddressPattern = "[a-zA-Z][a-zA-Z0-9._-]+@[a-z0-9.-]+\\.+[a-z]+[a-zA-Z]";
    return inputString.matches(emailAddressPattern);
}

From source file:com.playonlinux.core.utils.FileAnalyser.java

/**
 * Identify which line delimiter is used in a file
 * @param fileContent string to analyse/*from w ww .  ja v a  2  s  .c  o m*/
 * @return the line separator as a string. Null if the file has no line separator
 */
public static String identifyLineDelimiter(String fileContent) {
    if (fileContent.matches("(?s).*(\\r\\n).*")) { //Windows //$NON-NLS-1$
        return "\r\n"; //$NON-NLS-1$
    } else if (fileContent.matches("(?s).*(\\n).*")) { //Unix/Linux //$NON-NLS-1$
        return "\n"; //$NON-NLS-1$
    } else if (fileContent.matches("(?s).*(\\r).*")) { //Legacy mac os 9. Newer OS X use \n //$NON-NLS-1$
        return "\r"; //$NON-NLS-1$
    } else {
        return "\n"; //fallback onto '\n' if nothing matches. //$NON-NLS-1$
    }
}

From source file:Main.java

/**
 * Check whether a ratio is valid./*  w  w  w. j a v a 2 s .  c  o m*/
 * @param    ratio   The string containing the proposed ratio.
 * @param    split   The amount of shares the ratio should be split in. 
 *          Pass less than 2 to avoid checking shares. 
 * @return    Whether ratio is valid for required shares.
 */
public static boolean validRatio(String ratio, int split) {
    boolean result = false;
    if (ratio.matches("^[0-9][0-9]*:[[0-9]:]*[0-9]*[0-9]$")) {
        Log.v(TAG, "Checking ratio " + ratio + " results follow...");
        Log.i(TAG, "RATIO PATTERN MATCHED");
        if (split > 1) {
            String[] ratios = ratio.split(":");
            if (ratios.length == split) {
                Log.i(TAG, "RATIO IS VALID, hoorah!");
                result = true;
            } else {
                Log.w(TAG, "INVALID AMOUNT OF SHARES, RATIO INVALID");
            }
        } else {
            result = true;
        }
    } else {
        Log.w(TAG, "INVALID RATIO");
    }
    return result;
}

From source file:Main.java

public static boolean isNumeric(String operand) {
    operand = operand.toUpperCase();/*from w ww . j  a  v a  2s  .co  m*/
    if (operand.contains("0X")) {
        return operand.matches("0[xX][0-9a-fA-F]+");
    }
    if (operand.contains("H")) {
        return operand.matches("\\d+[h|H]+");
    }

    return operand.matches("\\d+");

}

From source file:Main.java

public static int romanToInt(String romanNumber) {
    if (!romanNumber.matches("[IVXLCDM]+")) {
        // Not a roman number
        throw new NumberFormatException("Not a roman number: " + romanNumber);
    }//from   ww  w .java  2 s. c  om

    String num = "IVXLCDM";
    int[] value = { 1, 5, 10, 50, 100, 500, 1000 };
    int sum = 0;
    for (int i = romanNumber.length() - 1; i >= 0;) {
        int posR = num.indexOf(romanNumber.charAt(i));
        if (i > 0) {
            int posL = num.indexOf(romanNumber.charAt(i - 1));
            if (posR <= posL) {
                sum += value[posR];
                i--;
            } else {
                sum += value[posR] - value[posL];
                i -= 2;
            }
        } else { // i==0
            sum += value[posR];
            i--;
        }
    }
    // So now <code>sum</code> is the resulting number.
    return sum;
}

From source file:com.boundary.metrics.vmware.client.MeterManagerClientTest.java

public static boolean isRegExInteger(String str) {
    return str.matches("\\d+"); //match a number with optional '-' and decimal.
}

From source file:com.bsb.intellij.plugins.xmlbeans.utils.ValidationUtils.java

public static boolean isValidJvmMemoryParameter(String jvmMemoryParameter) {
    return StringUtils.isNotBlank(jvmMemoryParameter) && jvmMemoryParameter.matches(JVM_MEMORY_PARAM_REGEX);
}

From source file:Main.java

/**
 * Remove any whitespace text nodes from the DOM. Calling this before saving
 * a formatted document will fix the formatting indentation of elements
 * loaded from a different document./*  w w w  .j  a va  2  s . c  o m*/
 * 
 * @param node
 *            Node to remove whitespace nodes from
 * @param deep
 *            Should this method recurse into the node's children?
 */
public static void removeWhitespace(Node node, boolean deep) {
    NodeList children = node.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.TEXT_NODE && length > 1) {
            Node previous = child.getPreviousSibling();
            Node next = child.getNextSibling();
            if ((previous == null || previous.getNodeType() == Node.ELEMENT_NODE
                    || previous.getNodeType() == Node.COMMENT_NODE)
                    && (next == null || next.getNodeType() == Node.ELEMENT_NODE
                            || next.getNodeType() == Node.COMMENT_NODE)) {
                String content = child.getTextContent();
                if (content.matches("\\s*")) //$NON-NLS-1$
                {
                    node.removeChild(child);
                    i--;
                    length--;
                }
            }
        } else if (deep && child.getNodeType() == Node.ELEMENT_NODE) {
            removeWhitespace(child, deep);
        }
    }
}

From source file:Main.java

public static boolean isNumeric(Object num) {
    if ((num == null) || (num.toString().length() <= 0)) {
        return false;
    }// w w w.j  av a  2s  .co  m
    String str = num.toString();
    if (str.length() <= 0) {
        return false;
    }
    if (str.matches("\\d{1,}")) {
        return true;
    }
    if (str.matches("^((-\\d+)|(0+))$")) {
        return true;
    }

    return (str.matches("^[0-9]+(.[0-9]{1,3})?$"));
}