Java---URL正则

版权声明:巴啦啦小魔仙乌卡拉卡,变身---------------------------------------xiner https://blog.csdn.net/zhengsaisai/article/details/87086539
((http|ftp|https|udp)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?

示例:

public class Demo {
	public static void main(String[] args) throws IOException {
		String ip = "udp://225.100.100.100:6666";
		boolean b = ip.matches("((http|ftp|https|udp)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?");
		System.out.println(b);
	}
}

猜你喜欢

转载自blog.csdn.net/zhengsaisai/article/details/87086539