C# Regex Tester

Test your regular expressions against any string and see instant match highlighting. The generated C# code uses System.Text.RegularExpressions and is ready to paste into your project.

//g
Flags

Match Highlights

11 matches
Hello, World! This is a C# Regex Tester. Match Words that Start With a Capital Letter.

Match Details

1
"Hello"index 0, length 5
2
"World"index 7, length 5
3
"This"index 14, length 4
4
"Regex"index 27, length 5
5
"Tester"index 33, length 6
6
"Match"index 41, length 5
7
"Words"index 47, length 5
8
"Start"index 58, length 5
9
"With"index 64, length 4
10
"Capital"index 71, length 7
11
"Letter"index 79, length 6

Generated C# Code

using System.Text.RegularExpressions;

string pattern = @"\b[A-Z][a-z]+\b";
string input = "your text here";

// Check if the pattern matches
bool isMatch = Regex.IsMatch(input, pattern);

// Get all matches
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
    Console.WriteLine($"Match: '{match.Value}' at index {match.Index}");

    // Access named or numbered capture groups
    for (int i = 1; i < match.Groups.Count; i++)
    {
        Console.WriteLine($"  Group {i}: '{match.Groups[i].Value}'");
    }
}

// Replace matches
string result = Regex.Replace(input, pattern, "replacement");

How to Use Regex in C#

C# uses the System.Text.RegularExpressions namespace for regex support. The static Regex class provides methods for matching, replacing, and splitting strings without instantiating an object.

Common C# Regex Methods

MethodReturnsDescription
Regex.IsMatch(input, pattern)boolTrue if the pattern matches anywhere in input
Regex.Match(input, pattern)MatchFirst match object (check .Success before using)
Regex.Matches(input, pattern)MatchCollectionAll non-overlapping matches
Regex.Replace(input, pattern, replacement)stringReplace each match with a replacement string
Regex.Split(input, pattern)string[]Split input at each regex match

C# RegexOptions (Flags)

Flag (this tester)C# OptionEffect
iRegexOptions.IgnoreCaseCase-insensitive matching
mRegexOptions.Multiline^ and $ match start/end of each line
sRegexOptions.Singleline. matches newline characters (\n)
RegexOptions.CompiledCompiles to IL for repeated high-performance use
RegexOptions.IgnorePatternWhitespaceAllows whitespace and comments inside the pattern

Common Regex Patterns for C#

PatternWhat it matches
\d+One or more digits (integer)
\d+\.\d+Decimal number
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Email address (basic)
^https?://URL starting with http:// or https://
\b\w{5}\bExactly 5-letter word
^\s*$Blank or whitespace-only line
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})ISO date with named groups