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 realize non-relation with or by using regular expression

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces how to use regular expressions to achieve and or non-relationship, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

1. 6 to 256 characters

two。 Includes at least three of the following four types of characters: numbers / lowercase letters / uppercase letters / other characters

3. Other rules that cannot be verified with regular expressions (such as minimum password modification time)

We can use the following regular expression to verify the validity of the password (where the blue and green parts are PatternA and PatternB, respectively):

(? = ^. {6255} $) (? =. *\ d) (? =. * [Amurz]) (? =. * [Amurz])) | (? =. * [^ A-Za-z0-9]) (? =. * [^ A-Za-z0-9]) | (? =. * [Amurz]) (? =. * [Amurz])) | (? = .*\) D) (? =. * [Amurz]) (? =. * [^ A-Za-z0-9]) ^. *

Write a regular expression that requires the matching string to satisfy condition A, but not condition B.

We can first write two subexpressions PatternA and PatternB to verify condition An and condition B, respectively. And then combine it into a new expression.

(PatternB) PatternA

For example, Windows Server's machine name is generally required to meet the following requirements (simplified from Microsoft's official requirements):

1. 2 to 15 characters. Can only include: numbers / lowercase letters / uppercase letters / minus signs

two。 Can't be all numbers.

We can verify the validity of the machine name with the following regular expression (where the blue part is PatternB and the green part is PatternA):

^ (?! ^\ dcm $) ([a-zA-Z0-9 -] {2jin15}) $

Write a regular expression that matches a string or satisfies either condition An or condition B.

We can first write two subexpressions PatternA and PatternB to verify condition An and condition B, respectively. And then combine it into a new expression.

(PatternA | PatternB)

For example, in an optional phone number field, the user can enter a legal phone number or leave it blank

We can verify the validity of the machine name with the following regular expression (where the blue part is PatternB and the green part is PatternA):

(^ $|\ d {719916})

Note: line start (^), line Terminator ($), and non-greed flag (?) The use here is very important.

On how to use regular expressions to achieve and or non-relationship is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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