Java Regex URL Validate isUrl(String test)

Here you can find the source of isUrl(String test)

Description

Checks if given string is uri.

License

Open Source License

Parameter

Parameter Description
test string to check.

Return

true if test matches URI_PATTERN, false otherwise.

Declaration

public static boolean isUrl(String test) 

Method Source Code

//package com.java2s;
/***********************************************************************************************************************
 * Copyright (c) 2008 empolis GmbH and brox IT Solutions GmbH. All rights reserved. This program and the accompanying
 * materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 * //from  w  w  w. j a  v  a  2  s .  com
 * Contributors: Dmitry Hazin (brox IT Solutions GmbH) - initial creator
 * Sebastian Voigt (brox IT Solutions GmbH)
 * 
    
 **********************************************************************************************************************/

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**
     * Pattern that checks if given string is URI (string begins and ends with word-char, contains no '>' or '<', has an
     * internal dot or slash).
     */
    private static final Pattern URI_PATTERN = Pattern
            .compile("(?:\\w|[\\.]{0,2}/)[\\S&&[^<>]]*(?:\\.|/)[\\S&&[^<>]]*(?:\\w|/)");

    /**
     * Checks if given string is uri.
     * 
     * @param test
     *          string to check.
     * @return true if test matches URI_PATTERN, false otherwise.
     */
    public static boolean isUrl(String test) {
        final Matcher uriMatcher = URI_PATTERN.matcher(test);
        return uriMatcher.find();
    }
}

Related

  1. isUrl(String aUrl)
  2. isURL(String f)
  3. isUrl(String s)
  4. isUrl(String s)
  5. IsUrl(String str)
  6. isUrl(String text)
  7. isURL(String url)
  8. isUrl(String url)
  9. isURL(String url)