Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

~
~
gms

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^\+\d{1,4}(( |\(| \(|-)?\d{1,4}( |\)|\) |-)?)?(\d{2} )?\d{2,4}[- ]?\d{2,3}[- ]?\d{0,2}$"; string input = @"+22-22-222-2222 +777(777)777-777 +666-66-666-6666 +9(999)999-9999 +444-444-444 +555(555)555-555 +0(000)000-0000 +1(111)111-1111 +11(111)111-1111 +111-11-111-111 +666-666-6666 +99 999 999 999 +77(777)777-7777 +999-99-999-99-99 +8(888)888-8888 +333-3333-3333 +000-00-000-000 +7(777)777-7777 +111(11)111-11-11 +55 555 55 55 55 +222-222-2222 +888-88-88-8888 +4(444)444-4444 +333-3-333-333 +555-5-555-5555 +555-55-5555 +666-66-666-666 +55-55-5555-5555 +999-999-9999 +5(555)555-5555 +666-666-6666 +111(111)111-111 +666-66-66-6666 +666-66-66-6666 +666-66-666-666 +000-0000-0000 +2 (222) 222-2222 +111(111)11-11 +999-999-9999 +0(000)000-0000 +555-55-55-5555 +444-44-44-44-44 +88-8-8888-8888 +11 11-11111111 +77(777)777-7777 +111-11-11111 +666(666)666-666 +999-99-999-9999 +777-77-777 +111 1111-1111 +666-66-666-666 +555-55-555-555 +33-3-333-3333 +666-666-6666 +222-22-222-222 +666(666)666-666 +55 55 55 55 55 +888-88-88-88-88 +5(555)555-5555 +7(777)777-7777 +111-1-111-1111 +66(666)666-6666 +111 1111-1111 +666-66-666-6666 +333-3-333-333 +000-000-0000 +222-22-222-2222 +666-66666 +777-777-777 +666-66-66666 +222 22 222 22 22 +33 3 33 33 33 33 +333-33333-3333 +777-77-77-77 +999-9-99-99-99 +555(555)55-55 +666(666)666-666 +55 555 5555555 +000(000)000-000 +000-000-00000 +55(555)555-5555 +444-44-44-44 +5(555)555-5555 +5(555)555-5555 +111 1111-1111 +444-44-444-444 +555-5-555555 +222-222-2222 +333 3333-3333 +000-0000-0000 +666 6666 6666 +88(888)888-888 +222 222 2222 +22 22222-22222 +77-77-777-77 +11(111)111-1111 +333(333)333-3333 +111 11 1111111 +999-9-999-9999 +99 999 999999 +7(777)777-7777 +99 999 99 9999 +000-0-0000-0000 +2 222 222-22-22 +444-444-444444 +222-22-222 +777-7777-7777 +111(111)111-111 +000-00-000-000 +444-44-444-444 +999-9-999-999 +111-1-111-1111 +888-88-888-888 +666-66-666-666 +333(333)333-3333 +666(666)66-666 +222(222)222-222 +111-1111-1111 +999-99-999-999 +222-22-22-22222 +555-5-5555-5555 +33 33-3333-3333 +000-000-0000 +222-22-22-2222 +333-3333-3333 +555-555-5555 +555(555)55-55-55 +111-11-11-1111 +777-777-7777 +11-11-11-1111 +999-999-9999 +666-6666-6666 +444-44-444-444 +111-11-11-1111 +999-99-999-999 +0(000)000-0000 +333-33-3333-333 +333-33-333-333 +33-333-333 +888-88-888-8888 +333-333-3333 +777-77-777-777 +44 44 44444444 +888-88-8888 +44 444-444-4444 +777-7777-7777 +444-44-44-4444 +222-22-222-22 +222-2222 +333-333-333 +222-222-222 +2(222)222-2222 +66 666 66 666 +666-66-666-666 +44 444-4444444 +666-666-6666 +555-55-555-5555 +000-000-0000 +666(666)66-666 +222(222)222-222 +44(444)444-444 +11 111 1111 +88 888-888-888 +222-22-222-2222 +111-1111-1111 +888-88888-8888 +99-99-999-9999 +2 222 222-22-22 +999(999)999-999 +4(444)444-4444 +6(666)666-6666 +2(222)222-2222 +999-99-9999 +111-1111-111111 +777-77-77777 +222-2-222-2222 +222-22-222-2222 +555-55-555-5555 +222-2-222-222 +222-22-222222 +11 1111-1111 +2(222)222-2222 +111(111)111-111 +777-77-777-777 +777-77777 +777-7-777-777 +99-99-999-9999 +44-44-444-4444 +222-22-222-2222 +77 777 777 777 +55-55-555-5555 +555-55-555-5555 +444-444-444 +999-99-99-9999 +77 77 777 77 77 +55 55 555 55 55 +999-99-9999-999 +999-9999-9999 +888-88-888-8888 +333-33-333-3333 +44-44-444-444 +222-222-2222 +777-77-777-777 +777-7777 +333-33333 +5(555)555-5555 +444-44-444-444 +44 444 444 44 44 +777-7-777-7777 +1(111)111-1111 +222-22222 +2(222)222-2222 +111(111)111-111 +000(00)000-00-00 +000-0-000-0000 +77 7777 777777 +2 (222) 222-2222 +666-6-666-66-66 +666-66-666-6666 +111-11111 +11 11 1111 1111 +00(000)000-0000 +33-33-3333-333 +444-44-4444 +444-4-444-444 +888-88-888-8888 +555-5-555555"; RegexOptions options = RegexOptions.Multiline | RegexOptions.Singleline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx