check URL by Regex - Java java.util.regex

Java examples for java.util.regex:Match URL

Description

check URL by Regex

Demo Code


//package com.java2s;
import java.util.regex.Pattern;

public class Main {

    public static boolean checkURL(String url) {
        String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
        return Pattern.matches(regex, url);
    }/*from w  w  w. j a v a2  s.co  m*/
}

Related Tutorials