java regular expression of knowledge

/ * Purpose: Regular Expressions
* Created: to Ieyasu
* Create date: 2019 April 21 9:59:08 PM
* /

// With the login screen of course, the regular expression you, it is necessary to do the project knowledge

// code through this blog, surely even the novice can fully grasp the basic use of regular expressions

// less code, comments, integrity, and strong purpose, just to let all desire for regular expressions novice can quickly master the basic skills

Pour package tone _ test regular expressions.;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Shi_1 class {public
// mail: [a-zA-Z _ ] {1,} [0-9] {0,} @ (([a-zA-z0-9] - *) {1,} \\. ) {l, 3} [a-zA-Z \\ -]. 1 {,}
// the name of the user ( combination of Chinese characters, letters, numbers ):?!?!.? ^ (_) (* _ $) [ Z0-9_-zA-a \ u4e00- \ u9fa5] + $
// password ( a combination of numbers and letters 6-16 ): (?! [0-9] + $)?! ^ ([a-zA- the Z] + $) [0-9A-Za-Z] {6,16} $
// phone number: ^ 1 [3 | 4 | 5 | 8] [0-9] \ d {8} $

public static void main(String[] args) {

To verify the string //
String STR = "17,873,364,643"; // name.getTeaxt ();
String str2 = "User Name 123abc";
String Str3 = "123456abcd1234567";


// regular expression
String rphoe = "^ 1 [3 | 4 | 5 | 8 | 7] [0-9] \\ d {8} $"; // phone number
String rname = "^ (_? !) (?!.? * _ $ ) [a-zA-Z0-9 _ \\ u4e00 - \\ u9fa5] + $ "; // username
String rpass =" ^ ([0-9 ] + $?!) ( ?! [a-zA-Z ] + $) [0-9A-Za-z] {6,16} $ "; // password


// regular expression compiler
the Pattern of Pattern.compile pphoe = (rphoe);
the Pattern of Pattern.compile pname = (RNAME);
the Pattern of Pattern.compile ppass = (rpass);

// start determination
Matcher mphoe = pphoe.matcher (str); // Analyzing telephone
Matcher mname = pname.matcher (str2); // if the username
Matcher mpass = ppass.matcher (str3); // password determination

// determination result
boolean phoe = mphoe.matches (); // telephone
boolean name = mname.matches (); // username
boolean pass = mpass.matches (); // password

System.out.println ( "phone" + PhoE);
System.out.println ( "user name" + name) ;
System.out.println ( "password" Pass +);

// ignore case the wording
// = the Pattern of Pattern.compile PAT (regEx, Pattern.CASE_INSENSITIVE);

}

}

 

Guess you like

Origin www.cnblogs.com/Xiangjiakang/p/10961227.html