# C# Regex Tester (.NET)

Test .NET/C# regular expressions online with named groups ((?…)), IgnoreCase/Multiline/Singleline options, match highlighting, capture-group tables, a ready-to-paste C# snippet and an IgnorePatternWhitespace preview.

> Canonical page: https://elysiatools.com/en/tools/csharp-regex-tester

- **Category:** Development

- **Keywords:** c# regex tester, csharp regex, .net regex online, regex online c#, system.text.regularexpressions, named groups, regexoptions, regular expression test

## Overview

A regex tester tuned to the .NET flavor used by C# and System.Text.RegularExpressions. Type the pattern exactly as you would in C# — named groups (?…) or (?'year'…), backreference \\k, RegexOptions flags — and the tester translates it to the platform's ECMAScript engine, runs it against your test string, and reports every match, every capture group (with names), and a replace preview using ${name} / $1 substitution syntax. It also prints ready-to-paste C# code with the right RegexOptions and match.Groups\["name"\] access. The report shows the translated pattern so you can see exactly what ran. .NET-specific facts are baked in: \\d \\w \\s are Unicode by default (toggleable), lookbehind may be variable length, and balancing groups (?…) plus \[a-z-\[aeiou\]\] class subtraction are detected and rejected with an explanation instead of mismatching silently. Note that .NET numbers unnamed groups before named ones — a quirk this emulator (like most engines) does not reproduce, so prefer named groups when order matters.

## Inputs

- **Pattern** (text): (?\\d{4})-(?\\d{2})
- **Test string** (textarea): Paste the text to match against…
- **i — IgnoreCase** (checkbox)
- **m — Multiline** (checkbox)
- **s — Singleline** (checkbox)
- **n — ExplicitCapture** (checkbox)
- **x — IgnorePatternWhitespace** (checkbox)
- **g — find all matches** (checkbox)
- **Replacement template (optional)** (text): ${name} / $1
- **Unicode character classes (\d \w \s match Unicode)** (checkbox)

## When to use

- You are building or debugging C# patterns using .NET-specific syntax like (?...) or \\k.
- You need to verify matching behavior with .NET RegexOptions like IgnoreCase, Multiline, Singleline, or IgnorePatternWhitespace.
- You want to generate copy-pasteable C# System.Text.RegularExpressions boilerplate and verify replacement strings before deploying code.

## How it works

- Enter your .NET regular expression pattern and provide test string text to match against.
- Toggle standard C# RegexOptions flags (IgnoreCase, Multiline, Singleline, ExplicitCapture, IgnorePatternWhitespace) and configure Unicode class behavior.
- Optionally enter a replacement template using ${name} or $1 syntax to preview substituted output.
- Inspect the highlighted matches, capture group breakdowns, and copy the generated C# System.Text.RegularExpressions code.

## Use cases

- Extracting structured fields like timestamps, IDs, or log levels from log files using named capture groups.
- Testing complex HTML or text templating patterns that rely on backreferences such as \\k or \\k'tag'.
- Validating input formats (dates, UUIDs, custom codes) while generating production-ready C# Regex validation methods.

## Frequently asked questions

### How do named groups work in this tester?

You can use either standard .NET named capture syntax: (?...) or (?'name'...). Captured values are displayed in a structured table and reflected in the generated C# snippet via match.Groups\["name"\].

### What replacement syntax is supported?

The tester supports .NET-style replacement placeholders, including named placeholders like ${name} and numeric capture groups like $1 or ${1}.

### Are character classes like \d, \w, and \s Unicode-aware?

Yes. By default, Unicode character class handling is enabled to match .NET behavior, but you can disable the toggle to restrict them to ASCII ranges.

### Are balancing groups and class subtractions supported?

Advanced .NET features like balancing groups (?...) and class subtractions \[a-z-\[aeiou\]\] are detected and reported with an explanatory notice rather than silently failing.

### Does this tool generate C# code automatically?

Yes. It creates a ready-to-paste C# snippet using System.Text.RegularExpressions.Regex configured with your chosen RegexOptions and group lookups.

## Related tools

- [Java Regex Tester](https://elysiatools.com/en/tools/java-regex-tester): Test java.util.regex patterns online: (?…) named groups, possessive quantifiers and atomic groups, Pattern flags, ASCII vs UNICODE\_CHARACTER\_CLASS \\d semantics, and ready-to-paste Java code.
- [Python Regex Tester (re module)](https://elysiatools.com/en/tools/python-regex-tester): Test Python re patterns online: (?P…) named groups, (?P=name) backreferences, VERBOSE patterns, findall behavior, and \\g replace templates — plus ready-to-paste Python code.
- [AI Regex Explainer](https://elysiatools.com/en/tools/ai-regex-explainer): Use AI to break down regular expressions into readable explanations
- [PCRE2 Regex Tester](https://elysiatools.com/en/tools/pcre-regex-tester): Test PCRE2 patterns online: every named-group syntax ((?P), (?), (\\u0027n\\u0027)), possessive quantifiers, atomic groups, \\A \\z \\h shorthands, plus pcre2grep and C API snippets.
- [Multi-Pattern Matcher](https://elysiatools.com/en/tools/multi-pattern-matcher): Match multiple regex patterns against text in one operation
- [Named Group Tester](https://elysiatools.com/en/tools/named-group-tester): Parse and display named capture groups from regex patterns
- [Regex Debugger](https://elysiatools.com/en/tools/regex-debugger): Step through how a regular expression matches a string position by position: visualize match attempts, partial successes, backtracks, and captures — a learning tool for understanding regex behavior, not just the final result
- [Regex Tester](https://elysiatools.com/en/tools/regex-tester): Test regular expressions against text

## Samples

- [Regex Named Capture Groups](https://elysiatools.com/en/samples/regex-named-groups): Collection of regex patterns using named capture groups for extracting structured data from text. Named groups make patterns more readable and maintainable by assigning meaningful names to captured portions.
- [Regex Replace Samples](https://elysiatools.com/en/samples/regex-replace): Collection of common and useful regex replacement patterns for text transformation and data cleaning
- [Common Regex Patterns](https://elysiatools.com/en/samples/regex-samples): Commonly used regular expression patterns for validation and matching
- [Regex Pattern Alternatives](https://elysiatools.com/en/samples/regex-alternatives): Multiple ways to write the same regex pattern with different trade-offs in readability, performance, and accuracy
