Java common regular expressions

Regular check tool : https://c.runoob.com/front-end/854

Reference from : http://blog.csdn.net/kiss_vicente/article/details/8050816

Common regular expressions:

  1. ^\d+$ // matches non-negative integers (positive integers + 0)
  2. ([1-9]{1}\\d*|\\d{1})[.]{0,1}\\d{0,2} //Judgment value (amount)
  3. ^[0-9]*[1-9][0-9]*$ //Matches positive integers 
  4. ^[1-9]\d*$ ////Match non-integer 
  5. ^[1-9]\d* ¦0$ //Matches non-negative positive integers
  6. ^((-\d+) ?(0+))$ // matches non-positive integers (negative integers + 0) 
  7. ^-[0-9]*[1-9][0-9]*$ //Matches negative integers 
  8. ^-?\d+$ // match integer 
  9. ^\d+(\.\d+)?$ // matches non-negative float (positive float + 0) 
  10. ^(([0-9]+\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]*\. [0-9]+) ?([0-9]*[1-9][0-9]*))$ //Match positive floating point numbers 
  11. ^((-\d+(\.\d+)?) ?(0+(\.0+)?))$ // matches non-positive floats (negative floats + 0) 
  12. ^(-(([0-9]+\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]* \.[0-9]+) ?([0-9]*[1-9] [0-9]*)))$ //Matches negative floating point numbers 
  13. ^(-?\d+)(\.\d+)?$ //Match floating point numbers 
  14. ^[A-Za-z]+$ //Matches a string consisting of 26 English letters 
  15. ^[AZ]+$ //Matches a string consisting of uppercase 26 English letters 
  16. ^[az]+$ //match a string consisting of 26 lowercase English letters 
  17. ^[A-Za-z0-9]+$ //Matches a string consisting of numbers and 26 English letters 
  18. ^\w+$ //Matches a string consisting of numbers, 26 English letters or underscores 
  19. ^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$ // match email address 
  20. [a-zA-z] +: // [^ \ s] * // Matching url 
  21. [\u4e00-\u9fa5] //Regular expression matching Chinese characters
  22. [^\x00-\xff] //Match double-byte characters (including Chinese characters)
  23. String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;} Calculate the length of the string (a double-byte character length counts as 2, ASCII character meter 1) 
  24. \n[\s ? ]*\r //regular expression matching blank lines
  25. / <(.*)>.* <\/\1> ? <(.*) \/>/ // Regular expression matching HTML tags
  26. (^\s*) ?(\s*$) //regular expression matching leading and trailing spaces
  27. [\u4e00-\u9fa5] //Regular expression matching Chinese characters
  28. \d{3}-\d{8} ?\d{4}-\d{7} //Matches domestic phone numbers 0511-4405222 or 021-87888822

 Regular Expression Use Cases

  1. ^\S+[az AZ]$ No //Can be empty, no spaces, only English letters 
  2. \S{6,} //Cannot be more than six digits 
  3. ^\d+$ //No spaces and no non-digits 
  4. (.*)(\.jpg ?\.bmp)$ //Only jpg and bmp formats 
  5. ^\d{4}\-\d{1,2}-\d{1,2}$ //Only 2004-10-22 format 
  6. ^0$ // choose at least one 
  7. ^0{2,}$ //Select at least two 
  8. ^[\s ?\S]{20,}$ //Cannot be more than 20 characters 
  9. ^ \ +? [A-z0-9] (([-+.]? [_] +)? [A-z0-9] +) * @ ([a-z0-9] + (\.? \ -)) + [az] {2,6} $ // Mail 
  10. \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([- +.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)* //Enter multiple addresses to separate emails with commas or spaces 
  11. ^([0−9]+)?[0-9]{7,8}$ Phone number with 7 or 8 digits or area code in front such as (022) 87341628 
  12. ^\w+@\w+(\.\w+)+(\,\w+@\w+(\.\w+)+)*$ //Can only be letters, numbers, underscores; there must be @ and . canonical mail


Match specific numbers: 
^[1-9]\d*$ //match positive integers 
^-[1-9]\d*$ //match negative integers 
^-?[1-9]\d*$ //match Integer 
^[1-9]\d* ¦0$ //matches non-negative integers (positive integers + 0) 
^-[1-9]\d* ¦0$ //matches non-positive integers (negative integers + 0) 
^[ 1-9]\d*\.\d* ¦0\.\d*[1-9]\d*$ //Matches positive float 
^-([1-9]\d*\.\d* ¦0 \.\d*[1-9]\d*)$ //Matches negative float 
^-?([1-9]\d*\.\d* ¦0\.\d*[1-9]\ d* ¦0?\.0+ ¦0)$ //Matches a float 
^[1-9]\d*\.\d* ¦0\.\d*[1-9]\d* ¦0?\.0+ ¦0$ //Matches non-negative floats (positive floats + 0) 
^(-([1-9]\d*\.\d* ¦0\.\d*[1-9]\d*)) ¦0 ?\.0+ ¦0$ // match non-positive float (negative float + 0) 


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325566762&siteId=291194637