XhCode Online Converter Tools

Regex Tester and generator

Regex Tester and generator helps you to test your Regular Expression and generate regex code for JavaScript PHP Go JAVA Ruby and Python.

Common Regular Expressions

Check digit expressions

  • Digit:
    ^[0-9]*$
  • N digits:
    ^\d{n}$
  • At least N digits:
    ^\d{n,}$
  • m-n digits:
    ^\d{m,n}$
  • Zero and non-zero start digits:
    ^(0|[1-9][0-9]*)$
  • Nonzero number with up to two decimal places:
    ^([1-9][0-9]*)+(.[0-9]{1,2})?$
  • A positive or negative number with one or two decimal places:
    ^(\-)?\d+(\.\d{1,2})?$
  • Positive, negative, and decimals:
    ^(\-|\+)?\d+(\.\d+)?$
  • A positive real number with two decimal places:
    ^[0-9]+(.[0-9]{2})?$
  • A positive real number with 1 to 3 decimal places:
    ^[0-9]+(.[0-9]{1,3})?$
  • A non-zero positive integer:
    ^[1-9]\d*$  or  ^([1-9][0-9]*){1,3}$  or  ^\+?[1-9][0-9]*$
  • A non-zero negative integer:
    ^\-[1-9][]0-9"*$  or  ^-[1-9]\d*$
  • Non-negative integers:
    ^\d+$  or  ^[1-9]\d*|0$
  • Non-positive integer:
    ^-[1-9]\d*|0$  or  ^((-\d+)|(0+))$
  • Non-negative floating-point numbers:
    ^\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$
  • 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 Float:
    ^-([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)$

Check character expressions

  • Alpha-Numeric Characters:
    ^[A-Za-z0-9]+$  or  ^[A-Za-z0-9]{4,40}$
  • All characters with a length of 3-20:
    ^.{3,20}$
  • A string of 26 letters:
    ^[A-Za-z]+$
  • A string of 26 uppercase English letters:
    ^[A-Z]+$
  • A string of 26 lowercase alphabetic characters:
    ^[a-z]+$
  • A string of numbers and 26 letters:
    ^[A-Za-z0-9]+$
  • A string of numbers, 26 letters, or an underscore:
    ^\w+$  or  ^\w{3,20}$
  • input with ^%&',;=?$\":
    [^%&',;=?$\x22]+
  • It is forbidden to input characters with ~:
    [^~\x22]+

Special Needs Expressions

  • Email:
    ^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
  • URL or Domain name:
    ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  • Date (MM/DD/YYYY)/(MM-DD-YYYY)/(MM.DD.YYYY)/(MM DD YYYY):
    ^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$
  • 12 months of the year(01~09 1~12):
    ^(0?[1-9]|1[0-2])$
  • 31 days a month(01~09 1~31):
    ^(0[1-9]|[12][0-9]|3[01])$
  • Password:
    ^.*(?=.{6,})(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[[email protected]#$%^&*? ]).*$
  • US Phone Numbers
    \b\d{3}[-.]?\d{3}[-.]?\d{4}\b
  • US Zip code
    ^[0-9]{5}(?:-[0-9]{4})?$
  • Slug
    ^[a-z0-9-]+$
  • All the special characters need to be escaped
    /[\-\[\]\/\\\{\}\(\)\*\+\?\.\^\$\|]/
  • xml file:
    ^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
  • Regular expressions for Chinese characters:
    [\u4e00-\u9fa5]
  • Double-byte characters:
    [^\x00-\xff] 
  • Blank line:
    \n\s*\r    (be used to delete blank lines)
  • HTML tags:
    <(\S*?)[^>]*>.*?|<.*? />
  • The leading and trailing whitespace character:
    ^\s*|\s*$ or (^\s*)|(\s*$)
  • IP address:
    ((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))
Regex Tester and Regex code generator Online Converter Tools

What is Regex Tester and Generator?

A Regex (Regular Expression) Tester and Generator is a tool that allows you to write, test, and debug regular expressions, or automatically generate regex patterns based on text patterns or rules. Regular expressions are powerful search patterns used for matching, validating, extracting, or replacing text.


Why Use Regex Tester and Generator?

  • Instant Feedback: Quickly see how your regex pattern matches input data.

  • Error Detection: Helps identify syntax errors or unintended matches.

  • Pattern Building: Automates the creation of complex expressions, saving time and reducing mistakes.

  • Learning Tool: Helps beginners understand how regex works through live examples and explanations.


How to Use Regex Tester and Generator?

  1. Regex Tester:

    • Input your regex pattern.

    • Enter test strings to see what matches.

    • View match highlights and capture groups.

  2. Regex Generator:

    • Provide sample text or describe a pattern (e.g., "email addresses" or "dates").

    • Let the tool generate a corresponding regex.

    • Optionally customize or refine the generated pattern.


When to Use Regex Tester and Generator?

  • When validating form input (e.g., email, phone number, postal code).

  • When extracting specific data from logs, documents, or code.

  • When replacing or formatting strings using text editors, scripts, or code.

  • When learning or debugging regex patterns for use in programming, automation, or text processing.