20 regular expressions are often used in front-end development.

1. Verify password strength: the strength of password must include the combination of upper and lower case letters and numbers. Special characters cannot be used, and the length is between 8 and 10

^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$

2. Check Chinese: the string can only be Chinese

^[\\u4e00-\\u9fa5]{0,}$

3. A string of numbers, 26 English letters or underscores

^\\w+$

4. Verify E-Mail address

[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?

5. Verify ID number
15 place

^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$

18 place

^[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)$

6. Verification date: "yyyy MM DD" format of date verification, which has considered flat leap year.

^(?:(?!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}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$

7. Verification amount: accurate to two digits

 ^[0-9]+(.[0-9]{2})?$

8. Verify mobile number: the following is the domestic mobile number regular expression starting with 13, 15 and 18. (the first two numbers can be extended according to the current domestic collection number)

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

9. Judge that the IE version has not been completely replaced. Many pages still need to be version compatible. The following is the expression of IE version check.

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

10. Verify IP-V4 address: IP4 regular statement

\\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

11. Verify IP-V6 address: IP6 regular statement

(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))

12. check the prefix of URL: in application development, it is often necessary to distinguish whether the request is HTTPS or HTTP. Through the following expression, a prefix of URL can be taken out and then judged logically

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

13. Extract URL link: the following expression can filter out the URL in a piece of text.

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

14. File path and extension verification: verify the file path and extension under windows (in the following example,. txt file)

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

15. Extract Color Hex Codes: sometimes you need to extract color codes from web pages. You can use the following expression.

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

16. Extract web page picture: if you want to extract all picture information in the web page, you can use the following expression.

\\< *[img][^\\\\>]*[src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*)

17. Extract page hyperlink: extract the hyperlink in html.

(<a\\s*(?!.*\\brel=)[^>]*)(href="https?:\\/\\/)((?!(?:(?:www\\.)?'.implode('|(?:www\\.)?', $follow_list).'))[^"]+)"((?!.*\\brel=)[^>]*)(?:[^>]*)>

18. Find CSS properties: through the following expression, you can search for matching CSS properties.

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

19. Extract comments: if you need to remove comments from HMTL, you can use the following expression.

<!--(.*?)-->

20. Match HTML tag: the tag attributes in HTML can be matched by the following expression.

<\\/?\\w+((\\s+\\w+(\\s*=\\s*(?:".*?"|'.*?'|[\\^'">\\s]+))?)+\\s*|\\s*)\\/?>

Author: craftsman
Link: https://www.jianshu.com/p/e7bb97218946
Source: Jianshu

Keywords: Mobile IE Windows

Added by sols on Mon, 04 May 2020 03:23:55 +0300