17 commonly used regular expression rules (covering most of the general needs)

For non professional programmers, regular expressions are relatively difficult. But in actual use, we can directly apply the existing cases. Here are 17 commonly used regular expression rules, which need to be copied directly.

1. Match Chinese characters

 [\u4e00-\u9fa5]

2. Match double byte characters

 [^\x00-\xff]

3. Match blank lines

 \n\s*\r

4. Match email address

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

5. Match URL

 [a-zA-z]+://[^\s]*

6. Match domestic phone number

 \d {3}- \d{8}|\d {4}- \{7,8}

7. Match QQ number

 [1-9][0-9]{4,}

8. Match China Postal Code

 [1-9]\d{5}(?!\d)

9. Match 18 digit ID card number

 ^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$

10. Match (year month day) date format

 ([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))

11. Match positive integers

 ^[1-9]\d*$

12. Match negative integers

 ^-[1-9]\d*$

13. Match Integer

 ^-? [1-9]\d*$

14. Match nonnegative integers

 ^[1-9]\d*|0$

15. Match non positive integers

 ^-[1-9]\d*|0$

16. Match floating point number

 ^[1-9]\d*\. \d*|0\. \d*[1-9]\d*$

17. Match negative floating point numbers

 ^-[1-9]\d*\. \d*|-0\. \d*[1-9]\d*$
Vote for you

Source: Lao Jiang Tribe » 17 commonly used regular expression rules (covering most of the general needs) |Welcome to share (public account: Chiang's circle of friends)

Get new information from webmaster/add QQ group from the public account "Chiang Kai shek's circle of friends"【 one billion twelve million four hundred and twenty-three thousand two hundred and seventy-nine 】Get preferential promotion from merchants