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.jslsolucoes.tagria.lib.util.TagUtil.java

public static String getLocalized(String label, JspContext jspContext) {
    if (label.matches("\\{(.*?)\\}")) {
        String key = label.replaceAll("(\\{|\\})", "").trim();
        try {//from www . ja  v  a  2  s .c om
            return ResourceBundle.getBundle("messages", locale(jspContext)).getString(key);
        } catch (MissingResourceException e) {
            logger.error("could not find key resource", e);
            return '!' + key + '!';
        }
    }
    return label;
}

From source file:at.tlphotography.jAbuseReport.Reporter.java

/**
 * Check line.//  w  w  w  . java  2s . c o m
 *
 * @param line
 *          the line
 * @return true, if successful
 */
private static boolean checkLine(String line) {

    String regex = ".*Authentication failure for .* from .*";

    return line.matches(regex);
}

From source file:nl.verheulconsultants.monitorisp.service.Utilities.java

/**
 * Check for a valid url (but omit checking the protocol header) or Ip4 or Ip6 address.
 *
 * @param urlString//w  w w. j ava2s. c  o m
 * @return
 */
public static boolean isValidHostAddress(String urlString) {
    //Assigning the url format regular expression
    String urlPattern = "^[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";
    return urlString.matches(urlPattern) || isValidIp(urlString);
}

From source file:com.kakao.hbase.common.Args.java

public static Set<String> tables(Args args, HBaseAdmin admin, String tableName) throws IOException {
    long startTimestamp = System.currentTimeMillis();
    Util.printVerboseMessage(args, Util.getMethodName() + " - start");
    if (tableName.equals(ALL_TABLES)) {
        Util.printVerboseMessage(args, Util.getMethodName() + " - end", startTimestamp);
        return null;
    } else {//from w  w w . ja  v a  2 s  .c  o m
        Set<String> tables = new TreeSet<>();
        HTableDescriptor[] hTableDescriptors = admin.listTables(tableName);
        if (hTableDescriptors == null) {
            return tables;
        } else {
            for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
                // fixme
                // If hbase 1.0 client is connected to hbase 0.98,
                // admin.listTables(tableName) always returns all tables.
                // This is a workaround.
                String nameAsString = hTableDescriptor.getNameAsString();
                if (nameAsString.matches(tableName))
                    tables.add(nameAsString);
            }
        }

        Util.printVerboseMessage(args, Util.getMethodName() + " - end", startTimestamp);
        return tables;
    }
}

From source file:Main.java

public static void autoCompleteTime(CharSequence text, EditText time, TextView timeHint) {
    String stringText = text.toString();

    String textToBeSet = "";
    int inputType = InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME;
    time.setError(null); //remove any error set from previously
    boolean error = false;

    if (stringText.matches("^\\d$")) {
        if (stringText.equals("1") || stringText.equals("0"))
            textToBeSet = "0:00AM";
        else {//from  w  ww.  ja  v  a2  s . co m
            textToBeSet = ":00AM";
        }
    } else if (stringText.matches("^\\d\\d$")) {
        int intText = Integer.parseInt(stringText);
        if (intText >= 0 && intText <= 12)
            textToBeSet = ":00AM";
        else
            error = true;
    } else if (stringText.matches("^\\d+:$"))
        textToBeSet = "00AM";
    else if (stringText.matches("^\\d+:\\d$"))
        textToBeSet = "0AM";
    else if (stringText.matches("^\\d+:\\d\\d$")) {
        int intText = Integer.parseInt(stringText.replaceAll("^\\d+:", "")); //get minutes
        if (intText > 0 && intText < 60) {
            inputType = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
            textToBeSet = "AM";
        } else
            error = true;
    } else if (stringText.matches("^\\d+:\\d\\d(A|P)$")) {
        inputType = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        textToBeSet = "M";
    } else if (stringText.equals(""))
        textToBeSet = "";
    else if (stringText.matches("^\\d+:\\d+(A|P)M")) {
        //To-do - take control to next input field
    } else {//error condition
        error = true;
    }

    if (error) {
        textToBeSet = "";
        time.setError("Incorrect time format");
    }

    time.setInputType(inputType);
    timeHint.setText(textToBeSet);

}

From source file:io.mangoo.build.Watcher.java

public static RuleMatch matchRule(Set<String> includes, Set<String> excludes, String string) {
    if (includes != null) {
        for (String regex : includes) {
            if (string.matches(regex)) {
                return new RuleMatch(true);
            }//from w  w w  .  j a v  a  2s .c o m
        }
    }

    if (excludes != null) {
        for (String exclude : excludes) {
            if (string.matches(exclude)) {
                return new RuleMatch(false);
            }
        }
    }

    return new RuleMatch(true);
}

From source file:com.dnastack.bob.service.processor.util.ParsingUtils.java

/**
 * Checks if there are multiple values given as a parameter.
 *
 * @param param values/*from   w  ww .ja v  a 2s  .c  om*/
 *
 * @return true/false
 */
public static boolean parameterHasMultipleValidValue(String param) {
    if (param == null) {
        throw new NullPointerException("param");
    }

    if (param.matches("\\[(((\\w)*-(\\w)*)*(\\w)*,)*((\\w)*-(\\w)*)*(\\w)*\\]")) {
        return true;
    }
    return false;
}

From source file:com.dnastack.bob.service.processor.util.ParsingUtils.java

/**
 * Checks if there is a single value given for the specified parameter.
 *
 * @param param parameter value//from www. j av a  2  s.  com
 *
 * @return true/false
 */
public static boolean parameterHasSingleValidValue(String param) {
    if (param == null) {
        throw new NullPointerException("param");
    }

    if (param.matches("[-a-zA-Z0-9]*")) {
        return true;
    }
    return false;
}

From source file:com.github.koraktor.steamcondenser.community.WebApi.java

/**
 * Sets the Steam Web API key/*  w w  w.  j  a  v a  2  s  .  co m*/
 *
 * @param apiKey The 128bit API key as a hexadecimal string that has to be
 *        requested from http://steamcommunity.com/dev
 * @throws WebApiException if the given API key is not a valid 128bit
 *        hexadecimal string
 */
public static void setApiKey(String apiKey) throws WebApiException {
    if (apiKey != null && !apiKey.matches("^[0-9A-F]{32}$")) {
        throw new WebApiException(WebApiException.Cause.INVALID_KEY);
    }

    WebApi.apiKey = apiKey;
}