In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what regular expressions are commonly used, which can be used for reference. I hope you can learn a lot after reading this article. Let's take a look at it.
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.
Var reg = / ^ (? =. *\\ d) (? =. * [Amurz]) (? =. * [Amurz]). {8Jing 10} $/
3. Check that the Chinese 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. To verify that the E-Mail address is the same as the password, 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 digits: 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 the date check in the format of "yyyy-mm-dd" has been taken into account in the leap year.
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 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 that the version of IE IE has not been completely replaced, many pages still need to be version compatible, the following is the expression of IE version check.
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 web images if you want to extract all the picture information in the web page, you can use the following expression.
Var reg = /\\
< *[img][^\\>] * [src] * = * [\ "\'] {0Power1} ([^\"\'>] *) /
18. Extract page hyperlinks extract hyperlinks in html.
Var reg = / (] *) (href= "https?:\ /\ /) ((?! (: (?: www\\.)? 'implode (' | (?: www\\.)', $follow_list).)) [^" rel= "external nofollow"] +) "((?. *\ 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 = / /; Thank you for reading this article carefully. I hope the article "what are the commonly used regular expressions" shared by the editor will be helpful to you? at the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.