Developer

Regex Basics: How Patterns, Flags and Character Classes Work

Regular expressions are a compact language for describing patterns in text, perfect for validation, search-and-replace, and parsing. How a regular expression is built, what the flags change, and the character classes you will use most. Applying these recommended techniques ensures high visual quality, faster page load speeds, and reliable performance across modern desktop and mobile web browsers.

Awais 2 min readPublished
Regex Basics: How Patterns, Flags and Character Classes Work

Regular expressions are a compact language for describing patterns in text, perfect for validation, search-and-replace, and parsing. They are also famously easy to get subtly wrong. The ToolOrbit Regex Tester lets you write a JavaScript pattern, see matches highlighted live against your sample text, and inspect each capture group as you type.

How a regex is built

A pattern is a mix of literal characters and metacharacters. Character classes match types of characters, quantifiers control repetition, and anchors tie a match to the start or end of a line. Parentheses create capture groups that pull out the parts you care about.

Pattern: (\d{4})-(\d{2})-(\d{2})
Text:    Release date: 2026-06-29
Group 1: 2026   Group 2: 06   Group 3: 29

Flags that change behavior

  • g (global): find all matches, not just the first
  • i (ignore case): match regardless of upper or lower case
  • m (multiline): make the anchors match at line breaks, not just string ends
  • s (dotall): let the dot match newline characters too
  • u (unicode): handle full Unicode code points correctly

The tester shows every match and its groups, so you can immediately see why a pattern caught too much or missed an edge case.

Warning: Watch for catastrophic backtracking. Patterns with nested quantifiers can hang on certain inputs. Prefer specific character classes and avoid overlapping repetition.

Using the Regex Tester

Enter your pattern and toggle the flags you need, then paste sample text to validate against. Live highlighting shows matches in place and the group panel breaks out each capture. Because everything runs in your browser, you can safely test against real log lines or data samples without uploading them anywhere.

Tips for cleaner patterns

Anchor your patterns when you mean to match a whole value, escape characters that have special meaning such as the dot and parentheses, and reach for named groups to make complex expressions readable. Remember that JavaScript regex differs from other engines in places, so test in the engine you will actually deploy to, which is exactly what this tester uses.

The character classes you will live in

Shorthand classes
ClassMatchesWatch out for
\dDigitsMatches Unicode digits too, not just 0–9
\wWord chars [A-Za-z0-9_]Underscore is included
\sWhitespaceIncludes tabs and newlines
\bWord boundaryNot a character — zero-width

Backtracking is where regex silently turns catastrophic: patterns with nested quantifiers like (a+)+ on pathological inputs can take hours (the classic ReDoS). If a pattern works on samples but a large input freezes the tester, that is the smell. Prefix-chedule your alternations, keep quantification flat, and test the worst case you can find before shipping the expression to production.


Tools mentioned

More reading

View all guides
Free Developer Tools Online: 2026 Developer Toolkit & Guides
Developer

Free Developer Tools Online: 2026 Developer Toolkit & Guides

Explore 30+ free browser-based developer tools: JSON formatters, Base64 converters, cron generators, regex testers, SQL formatters, and hash generators.

3 min readPublished
CSS Border Radius: 15 Copy-Paste Examples
Developer

CSS Border Radius: 15 Copy-Paste Examples

15 modern CSS border radius examples: rounded cards, pills, circle avatars, asymmetrical organic blobs, and fancy 8-value border radius shapes.

3 min readPublished
Percent Encoding Reference Table (Every Character)
Developer

Percent Encoding Reference Table (Every Character)

Complete percent encoding ASCII reference table: quick lookup for spaces, slashes, ampersands, punctuation, and UTF-8 special characters in URLs.

3 min readPublished
URL Encoding Explained: %20 vs +, Reserved Characters & Rules
Developer

URL Encoding Explained: %20 vs +, Reserved Characters & Rules

Complete guide to percent encoding in URLs: learn when to use %20 vs +, how reserved characters like & and ? work, and how to avoid encoding bugs.

3 min readPublished
Cron Every Hour, Day & Midnight: All Daily Schedules
Developer

Cron Every Hour, Day & Midnight: All Daily Schedules

Master standard daily cron schedules: cron every hour, every day at midnight, twice a day, and custom hourly intervals with copy-paste examples.

4 min readPublished
Cron Expression Cheat Sheet — Copy-Paste Schedule Examples
Developer

Cron Expression Cheat Sheet — Copy-Paste Schedule Examples

Free cron expression cheat sheet with copy-paste examples for every 5 minutes, hourly, daily at midnight, weekdays only, and more.

5 min readPublished
Cron Every 10 Minutes — Syntax, Examples and Best Practices
Developer

Cron Every 10 Minutes — Syntax, Examples and Best Practices

Use the cron expression */10 * * * * to run jobs every 10 minutes, plus examples for common schedules and troubleshooting tips.

3 min readPublished
Why CSV Is Tricky to Parse: Delimiters, Quotes and Headers
Developer

Why CSV Is Tricky to Parse: Delimiters, Quotes and Headers

Why CSV files are harder to read correctly than they look, how to choose the right JSON shape, and the mistakes to avoid.

2 min readPublished