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

Usage requirements of JS regular expressions

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "the usage requirements of JS regular expressions". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage requirements of JS regular expressions".

Let's introduce that JS regular expressions must contain numbers, letters, and special characters.

Js regular expressions require:

1. Must contain numbers, letters, special symbols and 8 digits or more

two。 Special symbols include: ~! @ # $% ^ & *

The regular expression is as follows:

/ ^ (? = .*\ d) (? = .* [a-zA-Z]) (? = .* [~! @ # $% ^ & *]) [\ damurzAmuri Zhuan salary percent ^ & *] {8,} $/

Explanation:

The positive foresight in js regular expression is mainly used here, for example.

/\ d/.exec ('abc2abc') match result is 2, definition: match a number

/\ d (? = a) / .exec ('abc2abc') matches 2, meaning: matches a number, but the number must be followed by the letter a

/\ d (? = a) / .exec ('abc2bc') match result is null

From this, we can see that the matching result does not contain the characters it matches, but the string to be matched must conform to its corresponding rules.

When there are multiple forward-looking rules, they are juxtaposed, not serial, such as

/\ d (? = a) (? = b) / .exec ('abc2abc') matches null, so if you want to match a number, it must be followed by the letters an and b.

/\ d (? = a) (? = .b) / .exec ('abc2abc'), of course, to demonstrate its rules, you can actually write /\ d (? = ab) / .exec (' abc2abc')

For / ^ (? =. *\ d) (? =. * [a-zA-Z]) (? =. * [~! @ # $% ^ & *]) [\ dalyzAmuri Zaoyuanqiao% ^ & *] {8,} $/

In fact, the whole regular representation can be divided into three parts:

/ ^ (? =. *\ d) [{8,} $/ ^ (? =. * [a-zA-Z]) {8,} $/ / ^ (? =. * [a-zA-Z]) {8,} $/ / ^ (? =. * [~! @ # $% ^ & *]) [\ daafezAmurZachi @ # $% ^ & *] {8,} $

The string to be matched must match these three parts at the same time.

Knowledge point expansion:

Js regular expressions match special characters except Chinese characters, letters, numbers, commas and periods (used to standardize input)

/ [^\ u4e00 -\ u9fa5a-zA-Z\ d,\.] + /

Where\ u4e00 -\ u9fa5 matches Chinese characters, a-zA-Z matches letters,\ d matches numbers,. Matches commas and periods, ^ for no, and + for as many matches as possible.

Thank you for your reading, the above is the content of "the usage requirements of JS regular expressions". After the study of this article, I believe you have a deeper understanding of the usage requirements of JS regular expressions, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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