Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Chinese matching of regular expressions

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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 * (?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report