LogoNavigation Menu

Regex Tool Guide: Online Regular Expression Testing & Common Patterns

Detailed guide on how to use online regex tool for pattern matching, debugging and validation. Includes common regex patterns, syntax explanations and practical use cases to help developers master regular expressions quickly.

Utily Team
2026-01-20
1596 views
Regex Tool Guide: Online Regular Expression Testing & Common Patterns

Why Do We Need a Regex Tool?

Regular Expression (Regex) is a powerful text matching and processing tool widely used for:

  • Form Validation:Validate email, phone number, URL formats
  • Data Extraction:Extract specific format data from text, such as dates, numbers, links
  • Text Replacement:Batch replace specific content in text
  • Log Analysis:Extract key information from log files
  • Code Search:Search for specific patterns in codebase

Using an online regex tool allows you to:

  • Quick Testing:Test regex in real-time and view match results immediately
  • Debug & Optimize:Quickly locate regex issues and optimize patterns
  • Learn Syntax:Quickly learn regex through common templates and syntax explanations
  • Improve Efficiency:Test regex without writing code, saving development time

How to Use the Regex Tool?

Visit the Regex Tool page and follow these steps:

  1. Enter the regex pattern in the "Regular Expression" input box
  2. Enter the text to match in the "Test Text" input box
  3. Select flags (g: global, i: case-insensitive, m: multiline)
  4. The system automatically displays match results including content, position and line number

Example

Regex:\d+
Test Text:I have 3 apples and 5 oranges
Match Results:Found "3" and "5"

Common Regex Patterns

The tool provides various common regex patterns that can be used directly:

1. Email Validation

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Matches standard email format, e.g.:user@example.com

Use Cases:Form validation, user registration, email format checking

2. Phone Number Validation (China)

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

Matches 11-digit Chinese phone numbers starting with 1, second digit 3-9.

Use Cases:Phone registration, SMS verification, user info validation

3. URL Validation

^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$

Matches HTTP or HTTPS URLs.

Use Cases:Link validation, URL extraction, web scraping

4. IP Address Validation

^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Matches IPv4 address format, e.g.:192.168.1.1

Use Cases:Network configuration, log analysis, IP validation

5. Date Format Validation

^\d{4}-\d{2}-\d{2}$

Matches YYYY-MM-DD date format, e.g.:2024-01-15

Use Cases:Date input validation, data formatting

6. Chinese Character Matching

[\u4e00-\u9fa5]

Matches a single Chinese character.

Use Cases:Chinese text extraction, character counting, text filtering

7. Username Validation

^[a-zA-Z0-9_]{3,16}$

Matches 3-16 character usernames containing only letters, numbers and underscores.

Use Cases:User registration, username validation

Regex Syntax Explained

Character Classes

  • . - Match any character except newline
  • \d - Match digit [0-9]
  • \D - Match non-digit
  • \w - Match word character [a-zA-Z0-9_]
  • \W - Match non-word character
  • \s - Match whitespace (space, tab, etc.)
  • \S - Match non-whitespace

Quantifiers

  • * - Match 0 or more times (greedy)
  • + - Match 1 or more times (greedy)
  • ? - Match 0 or 1 time
  • {n} - Match exactly n times
  • {n,} - Match at least n times
  • {n,m} - Match n to m times

Examples

\d{3}      → Match exactly 3 digits
\d{3,}     → Match at least 3 digits
\d{3,5}    → Match 3 to 5 digits
\d*        → Match 0 or more digits
\d+        → Match 1 or more digits

Anchors

  • ^ - Match start of string (line start in multiline mode)
  • $ - Match end of string (line end in multiline mode)
  • \b - Match word boundary
  • \B - Match non-word boundary

Examples

^hello      → Match string starting with "hello"
world$      → Match string ending with "world"
^hello$     → Exact match "hello"
\bword\b  → Match standalone word "word"

Groups and Capturing

  • () - Capturing group, can extract matched content
  • (?:) - Non-capturing group, for grouping without capturing
  • | - OR operator, match one of multiple options
  • [] - Character set, match any character in set
  • [^] - Negated character set, match characters not in set

Examples

(\d{4})-(\d{2})-(\d{2})  → Capture year, month, day
(?:red|green|blue)         → Match color but don't capture
[aeiou]                     → Match any vowel
[^0-9]                      → Match non-digit character

Flags Explanation

Regular expressions support the following flags:

  • g (Global):Match all occurrences, not just the first
  • i (Case-insensitive):Case-insensitive matching
  • m (Multiline):^ and $ match start and end of each line, not entire string

Example Comparison

Text:Hello hello HELLO
Regex:hello
- No flag:Match first "hello"
- g flag:Match all "hello", "hello", "HELLO"
- i flag:Match "Hello", "hello", "HELLO"
- gi flag:Match all (case-insensitive)

Usage Tips

1. Escape Special Characters

In regex, certain characters have special meanings. To match these characters literally, use backslash to escape:

Special chars:. * + ? ^ $ [ ] { } | ( ) \ /
Escape:\. \* \+ \? \^ \$ \[ \] \{ \} \| \( \) \\ \/

Example:Match decimal point

Wrong:3.14  → Match any char followed by 14
Right:3\.14 → Match "3.14"

2. Use Non-greedy Matching

By default, quantifiers are greedy (match as much as possible). Use ? to make them non-greedy:

Text:<div>Content1</div><div>Content2</div>
Greedy:<div>.*</div>  → Match entire string
Non-greedy:<div>.*?</div> → Match first <div>...</div>

3. Use Capturing Groups to Extract Data

Capturing groups can extract specific parts of matches:

Text:Date is 2024-01-15
Regex:(\d{4})-(\d{2})-(\d{2})
Match result:
  - Full match:2024-01-15
  - Group 1:2024 (year)
  - Group 2:01 (month)
  - Group 3:15 (day)

4. Testing and Debugging

Using online regex tools allows you to:

  • View match results in real-time, quickly locate issues
  • View match positions and line numbers for easy debugging
  • Test different flag combinations
  • Use common templates to get started quickly

Common Mistakes and Notes

1. Forgetting to Escape Special Characters

Wrong:\d+.\d+     → Match digit.any char digit
Right:\d+\.\d+   → Match decimal

2. Incorrect Quantifier Usage

Wrong:\d{1,}      → Correct syntax but not concise
Right:\d+         → Match 1 or more digits

3. Boundary Matching Issues

Text:hello world
Wrong:hello        → May match "hello" in "helloworld"
Right:\bhello\b  → Only match standalone word "hello"

4. Global Match Pitfalls

When using global flag g, the exec() method maintains lastIndex, which may cause unexpected match results. It's recommended to test in the tool before applying to code.

Conclusion

Regular expressions are very powerful tools in text processing. Mastering them can greatly improve development efficiency. Through the online regex tool, you can:

  • Quickly test and debug regular expressions
  • Learn common regex patterns
  • View detailed match results and position information
  • Use syntax explanations to quickly master regex
  • Improve efficiency in form validation, data extraction, etc.

The tool uses pure client-side processing. All data is processed locally in the browser and not uploaded to the server, ensuring data security. Supports real-time matching, multi-line text, global matching and more, making it a powerful assistant for developers.

You May Also Like

Regex Tool Guide: Online Regular Expression Testing & Common Patterns | Utily.cc