Skip to content
DocsAll
教程

Regular Expression Tutorial: Common Syntax and Online Testing Tool

Timi Tian · Published on May 8, 2026 · Updated on July 12, 2026
Regular ExpressionregexRegex TutorialRegex Test

What Is a Regular Expression

A regular expression (abbreviated as regex) is a mini-language for describing string patterns. A few lines of regex can accomplish text-processing tasks like "find all email addresses," "validate phone number format," or "replace all date formats."

Basic Syntax

Character Classes

Use square brackets to match any one of a set of characters:

  • [abc] matches a or b or c
  • [a-z] matches any lowercase letter
  • [0-9] matches any digit, equivalent to \d
  • [^abc] matches any character except a/b/c

Predefined Characters

  • \d digit, \D non-digit
  • \w letter, digit, or underscore, \W opposite
  • \s whitespace, \S non-whitespace
  • . any character (except newline)

Quantifiers

  • * zero or more times
  • + one or more times
  • ? zero or one time
  • {n} exactly n times, {n,m} n to m times

Grouping and Anchors

  • (...) capturing group
  • ^ start of line, $ end of line

Common Examples

Email Validation

^[\w.-]+@[\w.-]+\.\w{2,}$

Chinese Mobile Number

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

URL Extraction

https?://[\w./?=&%-]+

DocsAll Regex Testing Tool

The most effective way to learn regex is to write and test simultaneously. DocsAll provides an online regex testing tool, no environment setup required:

1. Enter the Regex

Type the regex in the expression input box and select modifiers (g global, i case-insensitive, m multiline).

2. Enter Test Text

Paste the content to match in the text box below.

3. View Results in Real Time

Matched content is highlighted, and all capture groups are listed.

Learning Tips

  • Start with simple examples, don't write complex regex right away
  • Use groups and named groups to improve readability
  • Remember the difference between greedy and non-greedy (*? +?)
  • Avoid nested quantifiers in performance-sensitive scenarios

Regular expressions seem hard to learn, but after mastering the basic syntax, practice more with the DocsAll regex testing tool and you'll become proficient within a week.

T
Timi Tian 创始人 / 全栈工程师

DocsAll 创始人,10 年全栈开发经验,专注浏览器端文档处理技术与隐私保护架构。前新加坡科技公司技术负责人。