The previous article simply wrote a regular expression of theoretical knowledge, this is the actual combat verification
First we write a URL validation class, of course, it can be another environment, here we have the Java environment
Package Com.zyt.regex;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
URL validation
public class Urlreg {
public String str = NULL;
Public String RegEX =null;
Ublic Boolean flag = false;
Public Boolean GetResult () {
//strings that need to be validated
//str = "https://yun.china-jado.com";
//str = "http://127.0.0.1:8080/pipeline/login.do?name=0";
//str = "http://localhost:8080;
str = "http://127.0.0.1:8888/zbmgys/map/mapIndex.jsp";
//Validation rules
RegEX = "^ ((ht|f) TPS?):/ /\\w+ (. \\w+) * ([\\[email protected]?^=%&:/~+#]*[\\[email protected]?^=%&:/~+#])? $ ";
//Compile regular Expressions
Pattern pattern = pattern.compile (RegEX);
Matcher Matcher = Pattern.matcher (str);
whether the string matches the regular expression
Boolean flag = Matcher.matches ();
return flag;
}
}
And then what? How are the methods written to verify?
Write a test class again.
Package Com.zyt.regex;
public class Regextest {
public static void Main (string[] args) {
Url
Urlreg url = new Urlreg ();
Boolean Result=url.getresult ();
System.out.print ("URL:" +result);
}
}
Well, to this, a verification URL matches the example of a regular expression to write well,, other mailboxes, cell phone number, ID number, and so on, and so on, welcome message, Welcome to communicate!
Java Validation Regular expression