Summary of common PHP regular expressions

Source: Internet
Author: User


1. "^ d + $" // non-negative integer (positive integer + 0)

 

2. "^ [0-9] * [1-9] [0-9] * $" // positive integer

 

3. "^ (-d +) | (0 +) $" // non-positive integer (negative integer + 0)

 

4. "^-[0-9] * [1-9] [0-9] * $" // negative integer

 

5. "^ -? D + $ "// integer

 

6. "^ d + (. d + )? $ "// Non-negative floating point number (positive floating point number + 0)

 

7. "^ ([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// positive floating point number

 

8. "^ (-d + (. d + )?) | (0 + (. 0 + )?)) $ "// Non-positive floating point number (negative floating point number + 0)

 

9. "^ (-([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// negative floating point number

 

10. "^ (-? D +) (. d + )? $ "// Floating point number

 

11. "^ [A-Za-z] + $" // A string consisting of 26 English letters www.netxu.com

 

12, "^ [A-Z] + $" // a string consisting of 26 uppercase letters

 

13. "^ [a-z] + $" // a string consisting of 26 lowercase letters

 

14. "^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters

 

15. "^ w + $" // a string consisting of a number, 26 letters, or underscores

 

16. "^ [w-] + (. [w-] +) * @ [w-] + (. [w-] +) + $" // email address

 

17. "^ [a-zA-z] +: // (w + (-w + )*)(. (w + (-w + )*))*(? S *)? $ "// Url

 

18,/^ (d {2} | d {4})-(0 ([1-9] {1}) | (1 [1 | 2]) -([0-2] ([1-9] {1}) | (3 [0 | 1]) $ // year-month-day

 

19,/^ (0 ([1-9] {1}) | (1 [1 | 2]) /([0-2] ([1-9] {1}) | (3 [0 | 1]) /(d {2} | d {4}) $ // month/day/year

 

20. "^ ([w-.] +) @ ([0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }.) | ([w-] + .) +) ([a-zA-Z] {2, 4} | [0-9] {1, 3}) (]?) $ "// Emil

 

21,/^ (+? [0-9] {2, 4}-[0-9] {3, 4}-) | ([0-9] {3, 4 }-))? ([0-9] {7,8}) (-[0-9] + )? $ // Phone number www.netxu.com

 

22. "^ (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]).

(D {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]) $ "// IP address

 

23. Regular Expression Matching Chinese characters: [u4e00-u9fa5]

 

24. Match double byte characters (including Chinese characters): [^ x00-xff]

 

25. Regular expression for matching empty rows: n [s |] * r

 

26. Regular expressions matching HTML tags:/<(. *)>. * </1> | <(. *)/>/

 

27. Regular expression matching spaces at the beginning and end: (^ s *) | (s * $)

 

28. Regular expression matching the Email address: w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w + )*

 

29. Regular expression matching URL: ^ [a-zA-z] +: // (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $

 

30. Check whether the matched account is valid (starting with a letter, may be 5-16 bytes, can contain letters and numbers underline): ^ [a-zA-Z] [a-zA-Z0-9 _] {} $

 

31. Match the Chinese phone number: (d {3}-| d {4 }-)? (D {8} | d {7 })?

 


32. Match Tencent QQ number: ^ [1-9] * [1-9] [0-9] * $

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.