Chinese regular expression matching - matching the regular Chinese

Original link: http://caibaojian.com/zhongwen-regexp.html

This article focuses on how to use the regular match Chinese characters, Chinese regular matching regular expression unlike other regular rules as easy to remember, take a look at the following Chinese regular expression is kind of how.

\ W matches only the Chinese, numbers, letters, for the people concerned, only matching Chinese often used, see below

Chinese characters matching the regular expression: [\ u4e00- \ u9fa5]

Perhaps you also need to match double-byte characters, but also double-byte Chinese characters

Match double-byte characters (including Chinese characters included): [^ \ x00- \ xff]

Note: can be used to calculate the length of the string (a double-byte character length meter 2, ASCII characters are counted 1)

More commonly used regular expression matching rules:

Letters: [a-zA-Z] 

figures: [0-9]

Matching Chinese, English letters and numbers and _:

'[\ U4e00- \ u9fa5_a-ZA-Z0-9] + $

While the input length determination: ·

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

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

1, a regular expression containing only characters, numbers, letters, underscores can not start and end with an underscore:

'(?! _) (?!. *? _ $) [A-ZA-Z0-9_ \ u4e00- \ u9fa5] + $

among them:

^ Place with the beginning of the string match

(?! _) Can not begin with _ 

(?!. *? _ $) Can not end _ 

[A-zA-Z0-9_ \ u4e00- \ u9fa5] + at least one Chinese characters, numbers, letters, underscores

$ End of string matching and local

// code from http://caibaojian.com/zhongwen-regexp.html 
on the program in front of the @, or need to be escaped \\ @ "^ (?! _) (?!. *? _ $) [ Z0-9_-zA-A \ u4e00- \ u9fa5] + $ " 

(or: @" ^ (_) \ w * (<_) $ " or @" ^ [\ u4E00- \ u9FA50-9a ?!?! -zA-Z _] + $ " )

2, contains only characters, numbers, letters, underline, the underline position is not limited:

'[A-ZA-Z0-9_ \ u4e00- \ u9fa5] + $

3, a string of numbers, letters or underscore 26 composed of

^\w+$

4,2 to 4 characters

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

5、

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

With: (Abc) + Analysis for: XYZAbcAbcAbcXYZAbcAb


Source: front-end development blog

Guess you like

Origin www.cnblogs.com/youyouyunduo/p/11706688.html
Recommended