Regular expressions that match any character, including English and Chinese punctuation

Source: Internet
Author: User
Tags regular expression
Regular expressions that match any character, including both English and any punctuation Regex: \\w*|\\w*| [\\u4e00-\\u9fa5] This expression matches an arbitrary Chinese-English character.Where: \w:a word character: [a-za-z_0-9] (matches a word character); Where: \w:a non-word character: [^\w] (match a non-word character); Where: [\\u4e00-\\u9fa5]: Match a Chinese character;

ref:http://saltdstar.iteye.com/blog/1041690
Ref:http://www.jb51.net/article/19713.htm
ref:http://www.jb51.net/article/64301.htm Test Cases:

Package cn.mike.march;

public class Matchesallcharactersincludechinese {public

    static void Main (string[] args) {

        String Singlewordregex = "\\w*|\\w*| [\\u4e00-\\u9fa5] ";
        String chinesecharacter = "Ben";
        System.out.println ("1_:" + chinesecharacter.matches (Singlewordregex));

        String Multiplewordsregex = "(\\w*|\\w*|[ \\u4e00-\\u9fa5]*) * ";
        String examplecharacters = "My days as Shine df134 Shine wsdf64?><?>|_!@@. :;... #$%%^&* (Ah ... ";
        System.out.println ("2_:" + examplecharacters.matches (Multiplewordsregex));

        String regex = "^[a-z]{1}" (\\w*|\\w*|[ \\u4e00-\\u9fa5]*) *[. ]{1}$ ";
        String ExampleChars3 = "B my god asdf13464?><?>|_!@@#$%%^&* (ah. ";
        System.out.println ("3_:" + examplechars3.matches (regex));
    }
}
/** Output:
    1_: True
    2_: True
    3_: true
*/
Appendix:Regular expression matching Chinese characters: [\u4e00-\u9fa5] matches double-byte characters (including kanji): [^\x00-\xff] In a text file, this expression can match all English:/[-~]/This expression can match all non-English (such as Chinese):/[^- ~]/
Note: There is a space in the middle of the expression; The Regular expression tool:JavaScript Regular expression Online test tool: http://tools.jb51.net/regex/javascript Regular expression online generation tool: Http://tools.jb51.net/regex/create_reg

by Mike Sun @ 20170330

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.