Java Regex URL Validate isUrl(String text)

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

Description

Tests if the given text is url.

License

Apache License

Parameter

Parameter Description
text the string to test

Return

returns true if the text is a url, otherwise false

Declaration

public static boolean isUrl(String text) 

Method Source Code

//package com.java2s;
/*/*from  ww  w .j  a  v  a 2 s . c o  m*/
 * This file is part of dependency-check-core.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
 */

import java.util.regex.Pattern;

public class Main {
    /**
     * A regular expression to test if a string is a URL.
     */
    private static final Pattern IS_URL_TEST = Pattern.compile("^(ht|f)tps?://.*", Pattern.CASE_INSENSITIVE);

    /**
     * Tests if the given text is url.
     *
     * @param text the string to test
     * @return returns true if the text is a url, otherwise false
     */
    public static boolean isUrl(String text) {
        return IS_URL_TEST.matcher(text).matches();
    }
}

Related

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