Here you can find the source of isUrlAddress(String text)
@SuppressWarnings("nls") public static boolean isUrlAddress(String text)
//package com.java2s; /* ****************************************************************************** * Copyright (c) 2006-2012 XMind Ltd. and others. * /* w w w . jav a 2 s . c o m*/ * This file is a part of XMind 3. XMind releases 3 and * above are dual-licensed under the Eclipse Public License (EPL), * which is available at http://www.eclipse.org/legal/epl-v10.html * and the GNU Lesser General Public License (LGPL), * which is available at http://www.gnu.org/licenses/lgpl.html * See http://www.xmind.net/license.html for details. * * Contributors: * XMind Ltd. - initial API and implementation *******************************************************************************/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { @SuppressWarnings("nls") public static boolean isUrlAddress(String text) { final String URL_REGEX = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; Pattern pattern = Pattern.compile(URL_REGEX); Matcher matcher; if (!text.contains("http://") && !text.contains("https://") && !text.contains("file://")) { matcher = pattern.matcher("http://" + text); } else { matcher = pattern.matcher(text); } return matcher.matches() && isLinkToWeb(text); } @SuppressWarnings("nls") public static boolean isLinkToWeb(String urlOrBookmark) { if (urlOrBookmark.contains("www.") || urlOrBookmark.contains(".com") || urlOrBookmark.contains(".cn") || urlOrBookmark.contains(".org") || urlOrBookmark.contains(".cc") || urlOrBookmark.contains(".net")) { return true; } return false; } }