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.khs.sherpa.processor.RestfulRequestProcessor.java

public String getAction(HttpServletRequest request) {
    final Pattern pattern = Pattern.compile("\\{\\d?\\w+\\}");

    Matcher matcher = null;/*from  w w  w. jav a 2 s .co m*/
    if (method.isAnnotationPresent(Action.class)) {
        for (String url : method.getAnnotation(Action.class).mapping()) {
            matcher = pattern.matcher(url);
            if (Pattern.matches(matcher.replaceAll("[^/]*"), UrlUtil.getPath(request))) {
                path = url;
            }
        }
    }
    return MethodUtil.getMethodName(method);
}

From source file:name.martingeisse.webide.workbench.WorkbenchPageServicesImpl.java

/**
 * /*from  www. j a  va  2 s .c  o m*/
 */
private String getDefaultEditorIdFromFilename(final String filename) {

    // TODO
    final long workspaceId = 1;
    final long userId = 1;

    final ExtensionQuery query = new ExtensionQuery(workspaceId, userId, "webide.editor.association");
    for (final ExtensionQuery.Result result : query.fetch()) {
        final JsonAnalyzer editorAssociation = new JsonAnalyzer(result.getDescriptor());
        final String targetType = editorAssociation.analyzeMapElement("target_type").expectString();
        final String targetSpec = editorAssociation.analyzeMapElement("target_spec").expectString();
        if (targetType.equals("filename_pattern")) {
            if (Pattern.matches(targetSpec, filename)) {
                return editorAssociation.analyzeMapElement("editor").expectString();
            }
        } else {
            logger.error("unknown editor association target type: " + targetType);
        }
    }

    // TODO user a better default
    return "webide.editors.java";
}

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

/**
 * Verifica se a expresso  um CPNJ.//from   w  w  w .  j a v  a 2  s  .c  om
 * @param id a identificao a ser verificada.
 * @return verdadeiro se a expresso  um CPNJ.
 */
public static boolean isOwnerCNPJ(String id) {
    return Pattern.matches("^([0-9]{2,3}\\.[0-9]{3}\\.[0-9]{3}/[0-9]{4}-[0-9]{2})$", id);
}

From source file:com.cyclopsgroup.waterview.core.DefaultWaterview.java

/**
 * Override or implement method of parent class or interface
 *
 * @see com.cyclopsgroup.waterview.Waterview#handleRuntime(com.cyclopsgroup.waterview.RuntimeData)
 *///from w w w.ja  v  a  2s . c  o m
public void handleRuntime(RuntimeData runtime) throws Exception {
    Pipeline pipeline = null;
    for (Iterator i = pipelines.keySet().iterator(); i.hasNext();) {
        String pattern = (String) i.next();
        if (Pattern.matches('^' + pattern + '$', runtime.getRequestPath())) {
            pipeline = getPipeline(pattern);
            break;
        }
    }
    if (pipeline != null) {
        pipeline.handleRuntime(runtime);
    } else {
        //TODO do something here
    }
}

From source file:org.exoplatform.utils.ExoUtils.java

/**
 * Verifies that an account username contains allowed characters only.
 * //from  ww  w . j a  v  a  2s.c  o m
 * @param username the username to verify
 * @return true if only allowed characters are found, false otherwise.
 */
public static boolean isUsernameValid(String username) {
    return (username == null) ? false
            : Pattern.matches(ExoConstants.ALLOWED_ACCOUNT_USERNAME_CHARSET, username);
}

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

public static void buildJson3(HashMap<String, Object> json, String[] path) {
    if (path.length == 1) {
        HashMap<String, Object> newObj = new HashMap<>();
        newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
        newObj.put("files", new ArrayList<HashMap<String, Object>>());
        json.put(path[0], newObj);/*from   w  w  w  .j a va2  s .c om*/

    } else {
        HashMap<String, Object> current = (HashMap<String, Object>) json.get(path[0]);
        for (int i = 1; i < path.length; i++) {
            String currentName = path[i];
            if (Pattern.matches(extensionRegex, currentName)) {
                HashMap<String, Object> newFile = new HashMap<>();
                newFile.put("name", currentName);
                newFile.put("link", getLink(path));
                List filesList = (List) current.get("files");
                filesList.add(newFile);
            } else {
                if (containsName((List<Map>) current.get("dirs"), currentName)) {
                    List<Map> directories = (List<Map>) current.get("dirs");
                    current = (HashMap<String, Object>) directories.get(getObjByName(directories, currentName));
                } else {
                    HashMap<String, Object> newObj = new HashMap<>();
                    newObj.put("name", currentName);
                    newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
                    newObj.put("files", new ArrayList<HashMap<String, Object>>());
                    List dirsList = (List) current.get("dirs");
                    dirsList.add(newObj);
                }
            }
        }
    }
}

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

/**
 * ?/*w  ww.ja v  a  2s .  co m*/
 *
 * @param digit ??0-9
 * @return ??true?false
 */
public static boolean isDigit(String digit) {
    if (StringUtils.isBlank(digit)) {
        return false;
    }
    String regex = "\\-?[1-9]\\d+";
    return Pattern.matches(regex, digit);
}

From source file:idgs.jdbc.IdgsJdbcDriver.java

@Override
public boolean acceptsURL(String url) throws SQLException {
    return Pattern.matches(URL_PREFIX + ".*", url);
}

From source file:com.geewhiz.pacify.utils.FileUtils.java

/**
 * /*from w  w w  .j  a v  a 2  s .  co m*/
 * @param relativePath
 * @param regEx
 *            file separator should be unix file separator
 * @return
 */
public static Boolean matches(Path relativePath, String regEx) {
    // we need to convert it, otherwise we have to mess around with
    // backslash quoting and regex
    String unixFileformat = FilenameUtils.separatorsToUnix(relativePath.toString());
    return Pattern.matches(regEx, unixFileformat);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.person.AddPersonValidator.java

public void validate(Object command, Errors errors) {
    AddPersonCommand apc = (AddPersonCommand) command;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenname", "required.field");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "surname", "required.field");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dateOfBirth", "required.field");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", "required.field");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required.field");

    try {//w w  w  .  j a v  a 2 s.c om
        Date d = ControllerUtils.getDateFormat().parse(apc.getDateOfBirth());
        if (d.getTime() >= System.currentTimeMillis()) {
            errors.rejectValue("dateOfBirth", "invalid.dateOfBirth");
        }
    } catch (ParseException e) {
        errors.rejectValue("dateOfBirth", "invalid.dateOfBirth");
    }
    if (apc.getNote().length() > 255) {
        errors.rejectValue("note", "invalid.maxLength");
    }
    if (!apc.getPhoneNumber().isEmpty()) {
        try {
            if (apc.getPhoneNumber().charAt(0) == '+') {
                Long.parseLong(apc.getPhoneNumber().substring(1));
            } else {
                Long.parseLong(apc.getPhoneNumber());
            }

        } catch (NumberFormatException ex) {
            errors.rejectValue("phoneNumber", "invalid.phoneNumber");
        }

    }
    if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", apc.getGivenname())) {
        errors.rejectValue("givenname", "invalid.givenname");
    }
    if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", apc.getSurname())) {
        errors.rejectValue("surname", "invalid.surname");
    }

    if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", apc.getEmail())) {
        errors.rejectValue("email", "invalid.email");
    }
    if (!apc.getEmail().equals(apc.getOldEmail())) {
        if (personDao.usernameExists(apc.getEmail())) {
            errors.rejectValue("email", "inUse.email");
        }
    }
    apc.setOldEmail("");
}