The method of using regular expressions to match Chinese regular expressions

Time:2019-11-20

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 http://caibaojian.com/zhongwen-regexp.html
^[\u4e00-\u9fa5_a-zA-Z0-9]+$

At the same time, judge the input length:·

[\u4e00-\u9fa5_a-zA-Z0-9_]{4,10}

^[\w\u4E00-\u9FA5\uF900-\uFA2D]*$

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

^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$

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:

^[a-zA-Z0-9_\u4e00-\u9fa5]+$

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

^\w+$

4. 2-4 Chinese characters

@”^[\u4E00-\u9FA5]{2,4}$”;

5、

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

Analyze with: (ABC) +: xyzabcabcbxyzabcab

summary

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!