SoFunction
Updated on 2025-03-04

Detailed analysis of regular expressions + common examples

  • Enter a number starting with zero and non-zero: "^(0|[1-9][0-9]*)$".
  • Enter a positive real number with two decimals: "^[0-9]+(.[0-9]{2})?$".
  • Enter a positive real number with 1 to 3 decimal places: "^[0-9]+(.[0-9]{1,3})?$".
  • Enter a non-zero positive integer: "^"+?[1-9][0-9]*$".
  • Enter a non-zero negative integer: "^"-[1-9][]0-9"*$.
  • Enter a character with length 3: "^.{3}$".
  • Enter a string composed of 26 English letters: "^[A-Za-z]+$".
  • Enter a string composed of 26 capital English letters: "^[A-Z]+$".
  • Enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
  • Enter a string composed of numbers and 26 English letters: "^[A-Za-z0-9]+$".
  • Enter a string composed of numbers, 26 English letters, or underscores: "^"w+$".
  • Verify user password: "^[a-zA-Z]"w{5,17}$" The correct format is: start with a letter, length between 6 and 18, and can only contain characters, numbers and underscores.
  • Verify that it contains characters such as ^%&’,;=?$"": "[^%&’,;=?$"x22]+".
  • Only enter Chinese characters: "^["u4e00-"u9fa5]{0,}$"
  • Verify the email address: "^"w+([-+.]"w+)*@"w+([-.]"w+)*"."w+([-.]"w+)*$".
  • Verify InternetURL: "^http://(["w-]+".)+["w-]+(/["w-./?%&=]*)?$".
  • Verification phone number: "^("("d{3,4}-)|"d{3.4}-)?"d{7,8}$"The correct format is: "XXX-XXXXXXX", "XXXX-XXXXXXXXX", "XXX-XXXXXXXXXXX, "XXX-XXXXXXXXXXXX, "XXXXXXXXXXXXXX, and "XXXXXXXXXXXXXXXXX.
  • Verify ID number (15 or 18 digits): "^"d{15}|"d{18}$".
  • The 12 months of verification for one year: "^(0?[1-9]|1[0-2])$" is correct format: "01"~"09" and "1"~"12".
  • Verify that the 31 days of one month: "^((0?[1-9])|((1|2)[0-9])|30|31)$" is correct format: "01"~"09" and "1"~"31".