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

What are the instances of web regular expressions

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the examples of web 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 what are the examples of web regular expressions.

Regular expression (regular expression) describes a string matching pattern (pattern), which can be used to check whether a string contains a certain substring, replace a matching substring, or extract a substring from a string that meets a certain condition.

1. Check the basic date format

Var reg1 = / ^\ d {4} (\-|\ / |\.)\ d {1Magne2}\ 1\ d {1Magne2} $/; var reg2 = / ^ (^ (\ d {4} |\ d {2}) (\-|\ |\.)\ d {1mag2}\ 3\ d {1can2} $) | (^ / d {4} years\ d {1pm 2} months\ d {1can2} day $)

two。 Check password strength

The strength of the password must be a combination of uppercase and lowercase letters and numbers, cannot use special characters, and is between 8 and 10 in length.

/ / the solution provided by netizens to detect special characters is var reg = / ^ (? =. *\ d) (? =. * [Amurz]) (? =. * [Amurz]). {8Jing 10} $/

3. Check Chinese

The string can only be in Chinese.

Var reg = / ^ [\\ u4e00 -\\ u9fa5] {0,} $/

4. A string consisting of numbers, 26 letters, or underscores

Var reg = / ^\\ wishbones /

5. Verify E-Mail address

As with passwords, the following is a regular check statement for E-mail address compliance.

Var reg = / [\\ wth / w / s /

6. Check ID card number

Here is the regular check of the ID card number. 15 or 18.

/ / 15 bits: var reg = / ^ [1-9]\\ d {7} ((0\\ d) | (1 [0-2])) (([0 | 1 | 2]\ d) | 3 [0-1])\\ d {3} $/ / / 18 bits: var reg = / ^ [1-9]\\ d {5} [1-9]\\ d {3} ((0\\ d) | (1 [0-2]) ([0 | 1 | 2]\\ d) | 3 [0-1])\\ d {3} ([0-9] | X) $/

7. Check date

Date check in "yyyy-mm-dd" format, taking into account flat leap years.

Var reg = / ^ (?: (! 0000) [0-9] {4}-(: 0 [1-9] | 1 [0-2])-(: 0 [1-9] | 1 [0-9] | 2 [0-8]) | (?: 0 [13-9] | 1 [0-2])-(?: 29 | 30) | (?: 0 [13578] | 1 [02])-31) | (?: [0-9] {2} (?) 48] | [2468] [048] | [13579] [26]) | (?: 0 [48] | [2468] [048] | [13579] [26]) 00)-02-29) $/

8. Check amount

Amount check, accurate to 2 decimal places.

Var reg = / ^ [0-9] + (. [0-9] {2})? $/

9. Check the mobile phone number

The following is the regular expression of the domestic mobile phone number at the beginning of 13, 15 and 18. (the first two opening digits can be expanded according to the current domestic collection number)

Var reg = / ^ (13 [0-9] | 14 [5 | 7] | 15 [0 | 1 | 2 | 3 | 6 | 7 | 8 | 9] | 18 [0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9])\\ d {8} $/

10. Determine the version of IE

IE has not been completely replaced yet, and many pages still need to be version compatible. Here are the expressions for IE version checking.

Var reg = / ^. * MSIE [5-8] (?:\. [0-9] +)? (?!. * Trident\ / [5-9]\ .0). * $/

11. Verify IP-v4 address

Var reg = /\ b (?: 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?)\\. {3} (?: 25 [0-5] | 2 [0-4] [0-9] | [01]? [0-9] [0-9]?)\ b /

twelve。 Verify IP-v6 address

Var reg = / ([0-9a-fA-F] {1 4}:) {7 9a-fA-F 7} [0-9a-fA-F] {1 9a-fA-F 4} | ([0-9a-fA-F] {1 9a-fA-F 4}:) {1 9a-fA-F 7}: ([0-9a-fA-F] {1 9a-fA-F 4}:) {1 5} (: [0-9a-fA-F] {1pm 4}) ) {1 9a-fA-F 2} | ([0-9a-fA-F] {1 9a-fA-F 4}:) {1 9a-fA-F 4} (: [0-9a-fA-F] {1 9a-fA-F 4}) {1 9a-fA-F 3} | ([0-9a-fA-F] {1 9a-fA-F 4}) {1pm 4} | ([0-9a-fA-F] {1pr 4}:) {1pm 2} (: [0-9a-fA-F] {1pm 4}) {1pm 5} | -fA-F] {19a-fA-F 4}: (: [0-9a-fA-F] {1 9a-fA-F 4}) {1 9a-zA-Z 6}) | (: (: [0-9a-zA-Z] {1 9a-zA-Z 4}) {1 9a-zA-Z 7} |:) | (: [0-9a-zA-Z] {0-9a-zA-Z] {1) | |:: (ffff (: 0 {0 9a-fA-F 4}) {0Power1}:) {0ffff 1} ((25 [0-5]) | (2 [0-4] | 1 {0Power1} [0-9]) {0Magne1} [0-9]) {0Magne1} (25 [0-5] | (2 [0-4] | 1 {0quotient 1} [0-9]) {0jin1} [0-9]) | ([0-0] 1}:) {1pm 4}: (25) [0-5] | (2 [0-4] | 1 {0rect 1} [0-9]) {0rect 1} [0-9])\\.) {3jue 3} (25 [0-5] | (2 [0-4] | 1 {0jue 1} [0-9])) /

13. Check the prefix of URL

In application development, it is often necessary to distinguish between HTTPS and HTTP. The following expression can be used to extract a url prefix and then logically judge.

If (! s.match (/ ^ [a-zA-Z] +:\ /\ /)) {s = 'http://' + s;}

14. Extract URL links

The following expression filters out the URL in a piece of text.

Var reg = / ^ (f | ht) {1} (tp | tps):\ / / ([\ w -] +\.) + [\ w -] + (\ / [\ w -. /?% & =] *)? /

15. File path and extension check

Verify the file path and extension under windows (.txt file in the following example)

Var reg = / ^ ([a-zA-Z]\\: |\)\ ([^\\] +\\) * [^\ /: *? "|] +\ .txt (l)? $/

16. Extract Color Hex Codes

Sometimes you need to extract the color code from a web page, you can use the following expression.

Var reg = / ^ # ([A-Fa-f0-9] {6} | [A-Fa-f0-9] {3}) $/

17. Extract pictures from web pages

If you want to extract all the picture information from the page, you can use the following expression.

Var reg = /\\

< *[img][^\\>

] * [src] * = * [\ "\'] {0Power1} ([^\"\'>] *) /

18. Extract page hyperlinks

Extract hyperlinks from html.

Var reg = / (] *) (href= "https?:\ /\ /) ((?! (: (?: www\\.)?'. Implode ('| (?: www\\.)', $follow_list).)) [^"] +) "(?. *\ brel=) [^ >] *) (?: [^ >] *) > /

19. Find the CSS attribute

With the following expression, you can search for a matching CSS attribute.

Var reg = / ^\\ s * [a-zA-Z\\ -] +\\ s * [:] {1}\\ s [a-zA-Z0-9\\ s.#] + [;] {1} /

20. Extract comments

If you need to remove comments from HMTL, you can use the following expression.

Var reg = / /

21. Convert thousand separator

Return total.toString () .replace (/\ B (? = (\ d {3}) + $) / g,',')

twenty-two。 Unified social credit code

The unified social credit code consists of 18 digits or capital letters, but the letters do not include I, O, Z, S, V

It is composed of five parts.

Part I: registration management department code 1 digit (number or capital letter)

Part II: organization category code 1 digit (number or uppercase letter)

Part III: the administrative region of the registration authority is coded with 6 digits (digits)

Part IV: subject identification code (organization code) 9 digits (numbers or uppercase letters)

Part V: check code 1 digit (number or uppercase letter)

The rules are as follows:

/ / 18 bits / [0-9A-HJ-NPQRTUWXY] {2}\ d {6} [0-9A-HJ-NPQRTUWXY] {10} / / 15 digits (there is still the old industrial and commercial registration code That is, 15-digit social credit code) / [1-9]\ d {15} / / support 18-digit and 15-digit unified social credit code / ^ ([0-9A-HJ-NPQRTUWXY] {2}\ d {6} [0-9A-HJ-NPQRTUWXY] {10} | [1-9]\ d {14}) $/ Thank you for your reading. That's what web regular expression examples are all about. After the study of this article, I believe that you have a deeper understanding of what web regular expression examples have, 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

Development

Wechat

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

12
Report