Matching domain name and IP of regular expression and problems needing attention in Java

Big data learning monk 2022-02-13 07:16:02 阅读数:64

matching domain ip regular expression

Regular expressions some commonly used expressions :

Email Address :

^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$

domain name :

[a-zA-Z0-9][-a-zA-Z0-9]{
0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{
0,62})+\.?

InternetURL:

[a-zA-z]+://[^\s]* or ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$

Phone number :

^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{
8}$

Phone number (“XXX-XXXXXXX”、“XXXX-XXXXXXXX”、“XXX-XXXXXXX”、“XXX-XXXXXXXX”、"XXXXXXX" and "XXXXXXXX):

^(\(\d{
3,4}-)|\d{
3.4}-)?\d{
7,8}$

Domestic phone number (0511-4405222、021-87888822):

\d{
3}-\d{
8}|\d{
4}-\d{
7}

Phone number regular expression ( Mobile number support ,3-4 Bit area code ,7-8 Bit live number ,1-4 Extension number ):

((\d{
11})|^((\d{
7,8})|(\d{
4}|\d{
3})-(\d{
7,8})|(\d{
4}|\d{
3})-(\d{
7,8})-(\d{
4}|\d{
3}|\d{
2}|\d{
1})|(\d{
7,8})-(\d{
4}|\d{
3}|\d{
2}|\d{
1}))$)

ID number (15 position 、18 Digit number ), The last bit is the check bit , May be a number or character X:

(^\d{
15}$)|(^\d{
18}$)|(^\d{
17}(\d|X|x)$)

Is the account number legal ( Beginning of letter , allow 5-16 byte , Allow alphanumeric underscores ):

^[a-zA-Z][a-zA-Z0-9_]{
4,15}$

password ( Start with a letter , The length is in 6~18 Between , Can only contain letters 、 Numbers and underscores ):

^[a-zA-Z]\w{
5,17}$

Strong password ( Must contain a combination of upper and lower case letters and numbers , Special characters cannot be used , The length is in 8-10 Between ):

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{
8,10}$

Strong password ( Must contain a combination of upper and lower case letters and numbers , Special characters can be used , The length is in 8-10 Between ):

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{
8,10}$

Date format :

^\d{
4}-\d{
1,2}-\d{
1,2}

One year 12 Months (01~09 and 1~12):

^(0?[1-9]|1[0-2])$

A month 31 God (01~09 and 1~31):

^((0?[1-9])|((1|2)[0-9])|30|31)$

Java Backslash regular expression syntax in

In other languages ,\ Express : I want to insert a normal ( Literal ) The backslash , Please don't give it any special meaning .

stay Java in ,\ Express : I want to insert a backslash of a regular expression , So the characters that follow are of special significance .

therefore , In other languages ( Such as Perl), A backslash \ It's enough to have the effect of escaping , And in the Java In regular expressions, there need to be two backslashes in order to be parsed into escape functions in other languages . It can also be simply understood in Java In the regular expression of , Two \ Represents one of the other languages \, That's why the regular expression for a number is \d, A normal backslash is \.

System.out.print("\\"); // Output is \
System.out.print("\\\\"); // Output is \\
copyright:author[Big data learning monk],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130716000129.html