Example usage for java.util.regex Pattern matches

List of usage examples for java.util.regex Pattern matches

Introduction

In this page you can find the example usage for java.util.regex Pattern matches.

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:de.fips.plugin.tinyaudioplayer.http.SoundCloudPlaylistProvider.java

@Rethrow(value = URISyntaxException.class, as = IllegalArgumentException.class)
@VisibleForTesting// w  w  w. j  a va 2 s  .co m
URI getSearchQueryURIFor(@NotNull @Normalize(Form.NFKC) final String searchText, final int pageNumber) {
    if (!Pattern.matches("[a-zA-Z0-9 ]+", searchText)) {
        throw new IllegalArgumentException();
    }
    return new URI(MessageFormat.format(SOUNDCLOUD_SEARCH_QUERY, pageNumber, toSearchString(searchText)));
}

From source file:functionalTests.annotations.AptTest.java

private Result getResults(BufferedReader stderr) {

    Result ret = new Result();

    try {// w ww.  jav  a2s  .c  o  m
        if (stderr.read() == -1) {
            // apt finished succesfully
            return ret;
        }

        for (String line = stderr.readLine(); line != null; line = stderr.readLine()) {
            System.err.println(line);
            if (Pattern.matches("\\d* error(s?)", line)) {
                ret.errors = extractNumber(line);
            }
            if (Pattern.matches("\\d* warning(s?)", line)) {
                ret.warnings = extractNumber(line);
            }
        }

        return ret;
    } catch (IOException e) {
        // return what we have up until now
        return ret;
    }

}

From source file:com.wyb.utils.util.PatternUtil.java

/**
 * ?URL?//  w w w.ja  v  a2 s. co m
 *
 * @param url ?http://blog.csdn.net:80/xyang81/article/details/7705960?  http://www.csdn.net:80
 * @return ??true?false
 */
public static boolean isURL(String url) {
    if (StringUtils.isNotBlank(url)) {
        String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
        return Pattern.matches(regex, url);
    }
    return false;
}

From source file:com.fanniemae.ezpie.common.StringUtilities.java

public static boolean isInteger(String value) {
    if (isNullOrEmpty(value))
        return false;
    value = value.trim();//from w ww . j a v  a 2 s  .co  m
    return (Pattern.matches("^[+-]?\\d+$", value) && (value.length() <= 8));
}

From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java

public static HashMap<String, Object> buildJson2(HashMap<String, Object> child, String[] path, boolean isFile,
        boolean isFirst) {
    if (path.length > 0) {
        String current = path[path.length - 1];
        HashMap<String, Object> res = new HashMap<>();
        res.put("name", current);
        if (Pattern.matches(extensionRegex, current)) {
            return buildJson2(res, Arrays.copyOf(path, path.length - 1), true, false);
        } else {/*from  w  w w. j a  v a2  s  . co m*/
            List childs = new ArrayList<>();
            if (!child.isEmpty()) {
                childs.add(child);
            }
            if (isFile) {
                res.put("files", childs);
            } else {
                res.put("dirs", childs);
            }
            return buildJson2(res, Arrays.copyOf(path, path.length - 1), false, false);
        }
    } else {
        return child;
    }
}

From source file:net.mindengine.oculus.frontend.service.jobs.runs.CheckTestRunForICTJob.java

private boolean checkReasonsCollation(IssueCollation collation, CronIctTestRun testRun) {
    if (collation.getReasonPattern() != null && !collation.getReasonPattern().isEmpty()) {
        if (testRun.getReason() == null) {
            testRun.setReason("");
        }/*  ww w  .ja  va 2s  .c o m*/

        ReportRender reportRender = new XmlReportRender();
        if (testRun.getReason() != null && !testRun.getReason().isEmpty()) {
            try {
                List<ReportReason> reasons = reportRender.decodeReasons(testRun.getReason());
                for (ReportReason reason : reasons) {
                    if (Pattern.matches(collation.getReasonPattern(), reason.getReason())) {
                        return true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    return false;
}

From source file:cz.maresmar.sfm.view.WithExtraFragment.java

/**
 * Test if extras in UI contains valid data
 *
 * @return {@code true} if data are valid, {@code false} otherwise
 *///  w w  w .java 2 s . co m
public boolean hasValidExtraData() {
    boolean isValid = true;

    int i = 0;
    for (ExtraFormat extraFormat : mExtrasFormat) {
        EditText extraEditText = mExtraUiBindings[i];

        if (extraFormat.valuesList.length == 0) {
            String extraValue = extraEditText.getText().toString();
            boolean matches = Pattern.matches(extraFormat.pattern, extraValue);

            if (!matches) {
                String errorText = getString(R.string.extra_value_not_follow_pattern_error,
                        extraFormat.pattern);
                extraEditText.setError(errorText);

                isValid = false;
            } else {
                extraEditText.setError(null);
            }
        }

        i++;
    }

    return isValid;
}

From source file:fr.univlorraine.mondossierweb.utils.Utils.java

public static String convertAnneeUnivToDisplay(String annee) {
    if (StringUtils.hasText(annee)) {
        if (Pattern.matches("^[0-9]{4}", annee)) {
            int anneeUniv = Integer.parseInt(annee);
            anneeUniv++;//from   w ww  .  ja va 2s.  co m
            annee += "/" + anneeUniv;
        }
    }
    return annee;
}

From source file:io.dacopancm.socketdcm.helper.HelperUtil.java

public static boolean isValidIP(String newValue) {
    String regex = "\\b((25[05]|2[04]\\d|[01]?\\d\\d?)(\\.)){3}(25[05]|2[04]\\d|[01]?\\d\\d?)\\b";
    return Pattern.matches(regex, newValue);
}

From source file:com.lurencun.cfuture09.androidkit.http.async.BinaryHttpResponseHandler.java

@Override
void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    byte[] responseBody = null;
    if (contentTypeHeaders.length != 1) {
        // malformed/ambiguous HTTP Header, ABORT!
        sendFailureMessage(new HttpResponseException(status.getStatusCode(),
                "None, or more than one, Content-Type Header found!"), responseBody);
        return;/*from   w  w  w .  ja v a 2  s  .c  o  m*/
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : mAllowedContentTypes) {
        if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
            foundAllowedContentType = true;
        }
    }
    if (!foundAllowedContentType) {
        // ??
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"),
                responseBody);
        return;
    }
    try {
        HttpEntity entity = null;
        HttpEntity temp = response.getEntity();
        if (temp != null) {
            entity = new BufferedHttpEntity(temp);
        }
        responseBody = EntityUtils.toByteArray(entity);
    } catch (IOException e) {
        sendFailureMessage(e, (byte[]) null);
    }

    if (status.getStatusCode() >= 300) {
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
                responseBody);
    } else {
        sendSuccessMessage(status.getStatusCode(), responseBody);
    }
}