Here you can find the source of isUrl(String test)
Parameter | Description |
---|---|
test | string to check. |
public static boolean isUrl(String test)
//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(); } }