Logo Wand.Tools

Regular Expression Generator

Intelligently generate and explain regular expressions, supporting various common pattern matching

Regular Expression Tutorial: From Beginner to Expert, Common Syntax and Examples Explained

Regular Expression (Regex) is a powerful pattern matching syntax for text search, extraction and replacement. It’s widely used in form validation, log analysis, data extraction, web crawling, and text processing.

For example:

  • Extract all email addresses from a text?
  • Validate a phone number?
  • Extract links from HTML?

All these can be easily done with regular expressions.

Basic Regex Syntax

Symbol Meaning
. Matches any character except newline
^ Matches start of input
$ Matches end of input
* Matches preceding element 0+ times
+ Matches preceding element 1+ times
? Matches preceding element 0 or 1 time
[] Matches any single character in brackets
[^] Matches any character NOT in brackets
{n} Matches exactly n times
{n,} Matches n or more times
{n,m} Matches between n and m times
\d Matches any digit (0-9)
\w Matches word character (a-z, A-Z, 0-9, _)
\s Matches whitespace character
` `
() Grouping for extraction or reference

Common Regex Examples

Chinese mobile number

^1[3-9]\d{9}$

Email validation

^[\w.-]+@[\w.-]+\.\w+$

URL matching

https?:\/\/(www\.)?[\w\-]+\.\w+(\.\w+)?(\/\S*)?

Regex in Different Languages

JavaScript

const regex = /\d{3}-\d{4}/;
const result = regex.test("123-4567");  // true

Python

import re
match = re.search(r"\d{3}-\d{4}", "Number: 123-4567")