Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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]
  • Character class intersection
    [\w&&[^\d]]
  • 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
Processing...

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(<!--\s*?export\s+?name[\:\=]([\'\""])[a-zA-Z]+?\w*?\2\s*?-->)[\s\S]+?((?=<!--\s*?export(\s+?name[\:\=]([\'\""])[a-zA-Z]+?\w*?\5)?\s*?-->)|(?:(?![\S\s])))"; string input = @"<body> <!-- export name:""PatientNameTh"" --> <th data-fieldname=""PatientPerson""> Name <span data-bind=""attr: { class: sortField() == 'PatientPerson' ? 'inline-block' : 'hide' }""></span> </th> other stuff <!-- export--> <td> <span class=""glyphicon glyphicon-expand""></span> <a data-bind=""click: function () { $root.loadReportSummary(PatientPerson.ID()) }""> <span data-bind=""text: $data.PatientPerson && $data.PatientPerson.FullName""></span> </a> </td> <!-- export --> <!-- export name:""StudyTypeTh"" --> <th data-fieldname=""StudyType"">Study Type <span data-bind=""attr: { class: sortField() == 'StudyType' ? 'inline-block' : 'hide' }""></span></th> <!--export name=""StudyTypeTd""--> <td data-bind=""text: $data.StudyType""></td> <!-- export --> <!-- export --> <!-- export name:""ServiceDateTh"" --> <th data-fieldname=""ServiceDate"">Service Date<span data-bind=""attr: { class: sortField() == 'ServiceDate' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""ServiceDateTd""--> <td data-bind=""text: $data.ServiceDate""></td> <!-- export name:""ExportSummaryTh"" --> <th>Export Summary</th> <!-- export name:""ExportSummaryTd""--> <td><a data-bind=""click: function (data) { $root.exportReportSummary(data, PatientPerson.ID, SummaryID, !StudyExported()) }"">View</a></td> <!-- export name:""PrintAllReportsTh"" --> <th>Print All Reports</th> <!-- export name:""PrintAllReportsTd""--> <td><a data-bind=""click: function (data) { $root.printAllReports('/PrintReports/Reports?summaryID=' + SummaryID) }"">Print</a></td> <!-- export name:""AssignStudyTh"" --> <th data-fieldname=""HasAssigned"">Assign<span data-bind=""attr: { class: sortField() == 'HasAssigned' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""AssignStudyTd""--> <td><a data-bind=""visible: !$data.StudyConfirmed, click: function () { $root.assignStudy($data.SummaryID) }"">Assign</a></td> <!-- export name:""FellowNameTh"" --> <th data-fieldname=""FellowPerson"">Fellow Name<span data-bind=""attr: { class: sortField() == 'FellowPerson' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""FellowNameTd""--> <td data-bind=""text: $data.FellowPerson && $data.FellowPerson.FullName""></td> <!-- export name:""AttendingNameTh"" --> <th data-fieldname=""AttendingPerson"">Attending Name<span data-bind=""attr: { class: sortField() == 'AttendingPerson' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""AttendingNameTd""--> <td data-bind=""text: $data.AttendingPerson && $data.AttendingPerson.FullName""></td> <!-- export name:""StudyConfirmedTh"" --> <th data-fieldname=""StudyConfirmed"">Study Confirmed<span data-bind=""attr: { class: sortField() == 'StudyConfirmed' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""StudyConfirmedTd""--> <td class=""text-center""><span class=""glyphicon glyphicon-ok"" data-bind=""visible: $data.StudyConfirmed"" /></td> <!-- export name:""StudyExportedTh"" --> <th data-fieldname=""StudyExported"">Study Exported<span data-bind=""attr: { class: sortField() == 'StudyExported' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""StudyExportedTd""--> <td class=""text-center""><span class=""glyphicon glyphicon-ok"" data-bind=""visible: $data.StudyExported()"" /></td> <!-- export name:""eMailViewTh"" --> <th data-fieldname=""EmailLogID"">Referral<span data-bind=""attr: { class: sortField() == 'EmailLogID' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""eMailViewTd""--> <td><a data-bind=""visible: $data.EmailLogID != 0"" class=""show-remote-modal"" data-target=""#myModal"" data-title=""Referral"" data-fullscreen=""true"">Print</a></td> <!-- export name:""Flag0Th"" --> <th data-fieldname=""Flag0"">Study Billed<span data-bind=""attr: { class: sortField() == 'Flag0' ? 'inline-block' : 'hide' }""></span></th> <!-- export name:""Flag0Td""--> <td><a href=""#"" data-bind=""text: $data.Flag0() ? 'Yes' : 'No', css: { stable: $data.Flag0(), critical: !$data.Flag0() }, click: setUnsetStudyBilled"" data-loader-message=""updating...""></a></td> <!-- export --> <!-- export name:""Flag0Td""--> <td><a href=""#"" data-bind=""text: $data.Flag0() ? 'Yes' : 'No', css: { stable: $data.Flag0(), critical: !$data.Flag0() }, click: setUnsetStudyBilled"" data-loader-message=""updating...""></a></td> </body>)"; foreach (Match m in Regex.Matches(input, pattern)) { 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