How to use Chinese matching of regular expressions
This article mainly introduces how to use regular expression Chinese matching, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
\ w matches only Chinese, numbers and letters. For Chinese people, only matching Chinese is often used, see below
Regular expressions that match Chinese characters: [\ u4e00 -\ u9fa5]
Maybe you also need to match double-byte characters. Chinese is also double-byte characters.
Match double-byte characters (including Chinese characters): [^\ X00 -\ xff]
Note: it can be used to calculate the length of a string (a double-byte character length meter 2recom ASCII character counter 1)
More common regular expression matching rules:
English letter: [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, determine the input length:
[\ u4e00 -\ u9fa5_a-zA-Z0-9 _] {4jue 10}
^ [\ w\ u4E00 -\ u9FA5\ uF900-\ uFA2D] * $
1. A regular expression that contains only Chinese characters, numbers, letters, and underscores cannot begin and end with an underscore:
^ (! _) (?!. *? _ $) [a-zA-Z0-9 _\ u4e00 -\ u9fa5] + $
Where:
^ matches the beginning of the string
(? _) cannot start with _
(?. *? _ $) cannot end with _
[a-zA-Z0-9 _\ u4e00 -\ u9fa5] + at least one Chinese character, number, letter, underscore
$matches the end of the string
Add @ before the program, otherwise you need to escape @ "^ (?! _) (?!. *? _ $) [a-zA-Z0-9 _ u4e00 -\ u9fa5] + $"
(or: @ "^ (?! _)\ w * (?