Online tools Toolshu.com Log In Sign Up

Online Regular Expression Tester

Online Tester
Instructions for use

Common Regular Expressions

1. Expressions for Validating Numbers

  • Number: ^[0-9]*$
  • n-digit number: ^\d{n}$
  • At least n digits: ^\d{n,}$
  • m-n digits: ^\d{m,n}$
  • Zero or non-zero starting number: ^(0|[1-9][0-9]*)$
  • Non-zero starting number with up to two decimal places: ^([1-9][0-9]*)+(\.[0-9]{1,2})?$
  • Positive or negative number with 1-2 decimal places: ^(\-)?\d+(\.\d{1,2})$
  • Positive, negative, and decimal numbers: ^(\-|\+)?\d+(\.\d+)?$
  • Positive real number with two decimal places: ^[0-9]+(\.[0-9]{2})?$
  • Positive real number with 1~3 decimal places: ^[0-9]+(\.[0-9]{1,3})?$
  • Non-zero positive integer: ^[1-9]\d*$ or ^([1-9][0-9]*){1,3}$ or ^\+?[1-9][0-9]*$
  • Non-zero negative integer: ^\-[1-9]\d*$ or ^-[1-9]\d*$
  • Non-negative integer: ^\d+$ or ^[1-9]\d*|0$
  • Non-positive integer: ^-[1-9]\d*|0$ or ^((-\d+)|(0+))$
  • Non-negative floating-point number: ^\d+(\.\d+)?$ or ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
  • Non-positive floating-point number: ^((-\d+(\.\d+)?)|(0+(\.0+)?))$ or ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
  • Positive floating-point number: ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ or ^(([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: ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ or ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
  • Floating-point number: ^(-?\d+)(\.\d+)?$ or ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$


2. Expressions for Validating Characters

  • Chinese characters: ^[\u4e00-\u9fa5]{0,}$
  • Alphabets and numbers: ^[A-Za-z0-9]+$ or ^[A-Za-z0-9]{4,40}$
  • String with length 3-20: ^.{3,20}$
  • String composed of 26 letters: ^[A-Za-z]+$
  • String composed of 26 uppercase letters: ^[A-Z]+$
  • String composed of 26 lowercase letters: ^[a-z]+$
  • String composed of numbers and 26 letters: ^[A-Za-z0-9]+$
  • String composed of numbers, 26 letters, or underscores: ^\w+$ or ^\w{3,20}$
  • Chinese, English, numbers, and underscores: ^[\u4E00-\u9FA5A-Za-z0-9_]+$
  • Chinese, English, numbers, but not including underscores or symbols: ^[\u4E00-\u9FA5A-Za-z0-9]+$ or ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
  • Allowing characters such as ^%&',;=?$\" etc.: [^%&',;=?$\x22]+
  • Prohibiting characters containing ~: [^~\x22]+

3. Special Requirement Expressions

  • Email address: ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
  • Domain name: [a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
  • Internet URL: [a-zA-z]+://[^\s]* or ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
  • Mobile 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}$
  • Phone number ("XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX"): ^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$
  • Domestic phone numbers (0511-4405222, 021-87888822): \d{3}-\d{8}|\d{4}-\d{7}
  • Phone number regex (supports mobile numbers, 3-4 digit area codes, 7-8 digit live numbers, 1-4 digit extensions): ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)
  • ID card number (15 digits, 18 digits, with the last digit as a checksum, possibly 'X'): (^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)
  • Account validity (starts with a letter, allows numbers and underscores, 5-20 characters): ^[a-zA-Z][a-zA-Z0-9_]{4,19}$
Comment area