The method of using regular expressions to match Chinese regular expressions


This article mainly talks about how to use regular matching to match Chinese characters. The matching rules of Chinese regular expressions are not as easy to remember as other regular rules. Let’s take a look at this Chinese regular expression.

\W matches only Chinese, numbers and letters. For Chinese people, matching only Chinese is often used. See the following

Regular expression matching Chinese characters: [\ u4e00 – \ u9fa5]

Maybe you also need to match double byte characters. Chinese is also a double byte character

Match double byte characters (including Chinese characters): [^ \ X00 – \ XFF]

Note: it can be used to calculate the length of string (one double byte character length meter 2, ASCII character meter 1)

More common regular expression matching rules:

English letters: [a-za-z]

Number: [0-9]

Match Chinese, English letters and numbers and \

//code from

At the same time, judge the input length:·



1. A regular expression containing only Chinese characters, numbers, letters and underscores cannot start and end with the following Dash:


Among them:

^Matches where the string starts

(?!? Cannot start with

(?!. *? $) cannot end with \

[a-za-z0-9 “, + at least one Chinese character, number, letter, underscore

$matches where the string ends

Put @ in front of the program, otherwise you need to \ \ escape @ “^ (?!) (?!. *? $) [a-za-z0-9″ + $”

(or: @ “^ (?!”) (? <! “$” or @ “^ [\ u4e00 – \ u9fa50-9a-za-z” + $”)

2. It only contains Chinese characters, numbers, letters and underscores, and the underscores are not limited to:


3. A string of numbers, 26 English letters or underscores


4. 2-4 Chinese characters




Analyze with: (ABC) +: xyzabcabcbxyzabcab


The above is the regular expression Chinese matching method of the Chinese regular expression matching problem introduced by Xiaobian to you. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!