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:com.bluexml.side.Framework.alfresco.notification.NotificationPolicy.java

protected String getSiteShortName(NodeRef node) {
    Path path = serviceRegistry.getNodeService().getPath(node);

    logger.debug("Node path :" + path);
    String regExpSiteName = ".*" + Pattern.quote(SiteModel.TYPE_SITES.toString()) + "/\\{[^}]*\\}([^/]+)/.*";

    String pathString = path.toString();
    String siteShortName = null;/*from  ww  w .j  a va  2  s . com*/
    if (Pattern.matches(regExpSiteName, pathString)) {
        // get site short name
        siteShortName = pathString.replaceFirst(regExpSiteName, "$1");
    }
    return siteShortName;
}

From source file:com.lovejoy777sarootool.rootool.preview.MimeTypes.java

private static boolean mimeTypeMatch(String mime, String input) {
    return Pattern.matches(mime.replace("*", ".*"), input);
}

From source file:dhbw.ka.mwi.businesshorizon2.ui.login.LogInScreenPresenter.java

/**
 * Prueft ob das Passwort den Sicherheitsbestimmungen entspricht und gibt
 * "true" fuer Entsprechnung und "false" fuer keine Entsprechung zurueck.
 * Wie im Fachkonzept beschrieben muss ein Passwort aus 6-20 Zeichen,
 * mindestens einer Zahl, Gru- und Kleinbuchstaben sowie einem
 * Sonderzeichen bestehen. Trifft das nicht zu, wird zudem eine
 * Fehlermeldung an die ViewImpl zur Ausgabe zurueckgegeben.
 * //from  ww  w .  j a v  a 2  s . co  m
 * @author Marcel Rosenberger, Annika Weis
 * @return Ob die beiden Passwrter gleich sind oder nicht
 */
private boolean validatePasswordSafety() {

    boolean safePassword;

    /**
     * hier wird das Passwort berprft
     * - 6 bis 20 Zeichen
     * - Gro- und Kleinbuchstaben entalten
     * - Ziffer enthalten
     * - Sonderzeichen enthalten
     * Erlaubte Sonderzeichen:
     * @ # $ % . , ; : ? ! ' |  ^  & _ - + / ( ) [ ] { } * "
     */
    if (Pattern.matches(
            "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%\\.,;\\:\\?!'|\\^&\\_\\-\\+/\\(\\)\\[\\]{}\\*\"]).{6,20})",
            password)) {
        safePassword = true;
        logger.debug("Passwort gengt Sicherheitsbestimmungen.");
    } else {
        safePassword = false;
        getView().showErrorMessage(
                "Das Passwort muss zwischen 6-20 Zeichen lang sein, sowie mindestens eine Zahl, Gro- und Kleinbuchstaben und ein Sonderzeichen enthalten.");
        logger.debug("Passwort gengt Sicherheitsbestimmungen nicht.");
    }

    return safePassword;

}

From source file:info.magnolia.cms.gui.dialog.DialogFckEdit.java

/**
 * @param value/*from  ww w .j a  v  a  2  s  .  c  om*/
 * @return
 */
private String convertToView(String value) {
    String tmp = value;
    if (tmp != null) {
        tmp = tmp.replaceAll("\r\n", "<br />"); //$NON-NLS-1$ //$NON-NLS-2$
        tmp = tmp.replaceAll("\n", "<br />"); //$NON-NLS-1$ //$NON-NLS-2$

        value = LinkUtil.convertUUIDsToAbsoluteLinks(value);

        Pattern imagePattern = Pattern.compile("(<(a|img)[^>]+(src|href)[ ]*=[ ]*\")([^\"]*)(\"[^>]*>)"); //$NON-NLS-1$

        Matcher matcher = imagePattern.matcher(value);
        StringBuffer res = new StringBuffer();
        while (matcher.find()) {
            String src = matcher.group(4);

            // process only internal and relative links
            if (!Pattern.matches("^\\w*://.*", src) && !src.startsWith("/")) {
                String link = this.getRequest().getContextPath() + this.getTopParent().getConfigValue("path")
                        + "/" + StringUtils.substringAfter(src, "/");

                matcher.appendReplacement(res, "$1" + link + "$5"); //$NON-NLS-1$
            }
        }
        matcher.appendTail(res);
        return res.toString();
    }

    return StringUtils.EMPTY;
}

From source file:com.ebixio.virtmus.stats.StatsLogger.java

/**
 * Gzips log files. It is safe to run this more than once on the same directory.
 * @param logsDir The directory to search for un-zipped logs.
 * @param logSet The log set to zip up./*from  w ww. j  a  va2s  .c  om*/
 */
private static void gzipLogs(File logsDir, final String logSet) {
    FilenameFilter logFilter = new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            // VirtMus-A-0.log, VirtMus-A-0.log.1
            return Pattern.matches("VirtMus-" + logSet + "-\\d+\\.log(\\.\\d+)*", name);
        }
    };

    // Zip up log files to be uploaded
    int counter = 0;
    for (File f : logsDir.listFiles(logFilter)) {
        String newName;
        File newFile;
        do {
            newName = String.format("%s%sVirtMus-%03d.gz", f.getParent(), File.separator, ++counter);
            newFile = new File(newName);
        } while (newFile.exists());

        if (gzipFile(f, newName)) {
            f.delete();
        }
    }
}

From source file:com.polyvi.xface.http.XHttpWorker.java

/**
 * url?/*from  www . ja  va  2 s .  c o  m*/
 * @param url:?url
 * @throws IllegalArgumentException
 */
private void checkUrlValid(String url) throws IllegalArgumentException {
    if (XStringUtils.isEmptyString(url) || !Pattern.matches(TAG_URL_REGEX, url)) {
        throw new IllegalArgumentException(TAG_URL_INVALID_MSG);
    }
}

From source file:net.spfbl.whois.Domain.java

public static boolean isValidEmail(String address) {
    if (address == null) {
        return false;
    } else {//ww w .  java 2s. c o  m
        address = address.trim();
        address = address.toLowerCase();
        if (Pattern
                .matches(
                        "^[0-9a-zA-Z._-]+" + "@" + "(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_-]{0,61}[a-zA-Z0-9])"
                                + "(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_-]{0,61}[a-zA-Z0-9]))*)" + "$",
                        address)) {
            int index = address.indexOf('@');
            String domain = address.substring(index + 1);
            return Domain.isHostname(domain);
        } else {
            return false;
        }
    }
}

From source file:net.spfbl.whois.SubnetIPv4.java

/**
 * Verifica se um CIDR  vlido na notao de IPv4.
 * @param cidr o CIDR a ser verificado./*from   w ww.  ja  v  a  2  s . c o m*/
 * @return verdadeiro se um CIDR  vlido na notao de IPv4.
 */
public static boolean isValidCIDRv4(String cidr) {
    if (cidr == null) {
        return false;
    } else {
        cidr = cidr.trim();
        return Pattern.matches("^" + "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]){1,3}\\.){1,3}"
                + "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/[0-9]{1,2}" + "$", cidr);
    }
}

From source file:com.xorcode.andtweet.TwitterUser.java

private static boolean isUsernameValid(String username) {
    boolean ok = false;
    if (username != null && (username.length() > 0)) {
        ok = Pattern.matches("[a-zA-Z_0-9\\.\\-\\(\\)]+", username);
        if (!ok && MyLog.isLoggable(TAG, Log.INFO)) {
            Log.i(TAG, "The Username is not valid: \"" + username + "\"");
        }/*from w w  w .j a v  a 2  s .c  o m*/
    }
    return ok;
}

From source file:com.wisemapping.exporter.FreemindExporter.java

private String rgbToHex(String color) {
    String result = color;//from   ww  w .  ja v  a 2 s .  c o  m
    if (color != null) {
        boolean isRGB = Pattern.matches("^rgb\\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}\\)$", color);
        if (isRGB) {
            String[] rgb = color.substring(4, color.length() - 1).split(",");
            Integer r = Integer.valueOf(rgb[0].trim());
            Integer g = Integer.valueOf(rgb[1].trim());
            Integer b = Integer.valueOf(rgb[2].trim());
            result = String.format("#%02x%02x%02x", r, g, b);
        }
    }
    return result;
}