Java regular expressions, Chinese character regularization, Java regular code

Source: Internet
Author: User
1. Regular expressions with letters, numbers, and underscores that cannot be preceded and terminated by an underscore: ^ (?!) _)(?!. *?_$) [a-za-z0-9_]+$        only letters and numbers: ^[a-za-z0-9_]+$   2. At least one Chinese character, number, letter, underline: [a-za-z0-9_\u4e00-\u9fa5]+          3. A regular expression of at least one Chinese character: "^[\u4e00-\u9fa5]"   4. Up to 10 characters: validationexpression= "^[\u4e00-\u9fa5]{0,10}"   5. Contains only Chinese characters, numbers, letters, underscores can not be underlined at the beginning and end: ^ (?!) _)(?!. *?_$) [a-za-z0-9_\u4e00-\u9fa5]+$       interpretation:             ^   where the string begins to match             (?! _) cannot start with _             (?!. *?_$) cannot end with _             [a-za-z0-9_\u4e00-\u9fa5]+ at least one Chinese character, number, letter, Underline             $ matches the end of the string      6. Email regular expression: Both options can be        (1) \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * &NBsp     (2) ^[_a-za-z0-9-]+ (\\.[ _a-za-z0-9-]+) *@[a-za-z0-9-]+ (\\.[ a-za-z0-9-]+) * (\\.[ A-za-z]{2,}) {1}$)   

Perfect e-mail regular expression:   International domain name format is as follows:                    domain names are composed of specific character sets, English letters, numbers, and "-" (i.e. hyphens or minus signs) of each country's characters, but neither the beginning nor the end of the,    can contain "-", "-"     cannot occur continuously.     domain letters are not case-sensitive. The domain name can be up to 60 bytes (including suffix. com,. NET,. org, and so on).                          /^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,3} ([\.] [A-z] {2})? $/i;               /content/i    form a case-insensitive regular expression;         ^    match start           $    matching end          [a-z]    e-mail prefix must be an English letter opening                 ([a-z0-9]*[-_ ]? [a-z0-9]+) *    And _a_2, Aaa11, _1_a_2 match, and A1_, Aaff_33a_, A__aa do not match, if it is a null character, is also a match, * represents 0 or more.          * Represents 0 or more preceding characters .         [a-z0-9]*     match 0 or more English letters or numbers          [-_]?    match 0 or 1 "-" because "-" cannot appear consecutively          [a-z0-9]+    matches 1 or more English letters or numbers, because "-" cannot be done at the end                 @    must have a @          ([a-z0-9]*[-_]?[ a-z0-9]+) +    See above ([a-z0-9]*[-_]?[ a-z0-9]+) * explanation, but cannot be null, + represents one or more.          [\.]     special characters (.) As a normal character          [a-z]{2,3}    match 2 to 3 English letters, generally COM or net, etc. .          ([\.] [A-z] {2})?     match 0 or 1 [\.] [A-z] {2} (e.g.. CN, etc.)     I don't know. com.cn the last part is not all two digits, if not please modify {2} to {start Word, end Word}    、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、  

 Perfect e-mail regular expression: The International Domain name format is as follows: The domain name is composed of the specific character set of the country text, the English letter, the numeral and "-" (that is, hyphen or minus sign) any combination, but the beginning and the end can not contain "-", "-" The letters in the domain name are not case-insensitive.     
    
    
  The domain name can be up to 60 bytes (including suffix. com,. NET,. org, and so on). /^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,3} ([\.] [A-z] {2})?   
    
  $/i;   
  /content/I forms a case-insensitive regular expression; ^ Match start $ match end [A-z] e-mail prefix must be an English letter opening ([a-z0-9]*[-_]?[   
  a-z0-9]+) * and _a_2, AAA11, _1_a_2 match, and A1_, Aaff_33a_, A__aa do not match, if it is a null character, is also a match, * represents 0 or more.   
  * Represents 0 or more preceding characters.   [a-z0-9]* matches 0 or more English letters or numbers [-_]? Match 0 or 1 "-" because "-" cannot appear consecutively [a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be done at the end @ must have a @ ([a-z0-9]*[-_]?[ a-z0-9]+) + See above ([a-z0-9]*[-_]?[   
  a-z0-9]+) * explanation, but cannot be null, + represents one or more.   [\.] The special character (.)   
  As a common character [a-z]{2,3} matches 2 to 3 English letters, generally COM or net. ([\.] [A-z]   {2})? Match 0 or 1 [\.] [A-z] {2} (for example, CN, etc.) I don't know. com.cn the last part is all two digits, if not please modify {2} to {Start Word, end words} 

The following is reproduced: Java code 1, a regular expression, only contains Chinese characters, numbers, letters, underscores can not be underlined at the beginning and end:   ^ (?!). _)(?!. *?_$) [a-za-z0-9_\u4e00-\u9fa5]+$   where:   ^   matches the start of the string    (?! _) cannot start with _    (?!. *?_$) can not end with _    [a-za-z0-9_\u4e00-\u9fa5]+ at least one Chinese character, number, letter, underscore    $ ending with string      Put @ in front of the program, or you need to escape @ ^ (?! _)(?!. *?_$) [a-za-z0-9_\u4e00-\u9fa5]+$]   (or: @) ^ (?!) _) \w* (? <!_) $ "        @" ^[\u4e00-\u9fa50-9a-za-z_]+$ "  )      2, only contain Chinese characters, numbers, letters, underscores, underline position not limited to:      ^[a-za-z0-9_\u4e00-\u9fa5]+$     3, by numbers, 26 English letters or underscore strings    ^\w+$     4, 2~4 Chinese characters       @ "^[\u4e00-\u9fa5]{2,4}$" ;     5,    ^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$     with: (ABC) +     to analyze:   xyzabcabcabcxyzabcab         XYZABCABCABCXYZABCAB6,    [^\u4e00-\u9fa50-9a-za-z_]   34555#5 '-->34555#5 '     [\u4e00-\u9fa50-9a-za-z_]     eiieng_ 89_   --->    eiieng_89_   _ '; eiieng_88&*9_    -->   _ '; ' eiieng_88&*9_   _ '; ' eiieng_88_&*9_  -->   _ '; ' eiieng_88_&*9_   

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

public bool Regexname (string str)

{

BOOL Flag=regex.ismatch (str,@ "^[a-za-z0-9_\u4e00-\u9fa5]+$");

return flag;

}

Regex reg=new Regex ("^[a-za-z_0-9]+$");

if (Reg. IsMatch (s))

{

\ Compliance Rules

}

Else

{

\ \ There are illegal characters

}

、、、、、、、、、、、、、、、、、、、、、、、、

Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;

Public list<map<string, String>> GetUser (String deptid) {

Pattern pattern = pattern.compile ("^[a-za-z0-9_]+$");

Matcher Matcher = Pattern.matcher (DeptID);

if (Matcher.find ()) {

If the match

}else{

does not match

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.