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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(<!--\\s*?export\\s+?name[\\:\\=]([\\'\\\"])[a-zA-Z]+?\\w*?\\2\\s*?-->)[\\s\\S]+?((?=<!--\\s*?export(\\s+?name[\\:\\=]([\\'\\\"])[a-zA-Z]+?\\w*?\\5)?\\s*?-->)|(?:(?![\\S\\s])))"; final String string = "<body>\n" + " <!-- export name:\"PatientNameTh\" -->\n" + " <th data-fieldname=\"PatientPerson\">\n" + " Name <span data-bind=\"attr: { class: sortField() == 'PatientPerson' ? 'inline-block' : 'hide' }\"></span>\n" + " </th>\n\n" + "other stuff\n\n" + " <!-- export-->\n" + " <td>\n" + " <span class=\"glyphicon glyphicon-expand\"></span>\n" + " <a data-bind=\"click: function () { $root.loadReportSummary(PatientPerson.ID()) }\">\n" + " <span data-bind=\"text: $data.PatientPerson && $data.PatientPerson.FullName\"></span>\n" + " </a>\n" + " </td>\n" + "<!-- export -->\n" + " <!-- export name:\"StudyTypeTh\" -->\n" + " <th data-fieldname=\"StudyType\">Study Type <span data-bind=\"attr: { class: sortField() == 'StudyType' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!--export name=\"StudyTypeTd\"-->\n" + " <td data-bind=\"text: $data.StudyType\"></td>\n" + " <!-- export -->\n" + " <!-- export -->\n" + " <!-- export name:\"ServiceDateTh\" -->\n" + " <th data-fieldname=\"ServiceDate\">Service Date<span data-bind=\"attr: { class: sortField() == 'ServiceDate' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"ServiceDateTd\"-->\n" + " <td data-bind=\"text: $data.ServiceDate\"></td>\n" + " <!-- export name:\"ExportSummaryTh\" -->\n" + " <th>Export Summary</th>\n" + " <!-- export name:\"ExportSummaryTd\"-->\n" + " <td><a data-bind=\"click: function (data) { $root.exportReportSummary(data, PatientPerson.ID, SummaryID, !StudyExported()) }\">View</a></td>\n" + " <!-- export name:\"PrintAllReportsTh\" -->\n" + " <th>Print All Reports</th>\n" + " <!-- export name:\"PrintAllReportsTd\"-->\n" + " <td><a data-bind=\"click: function (data) { $root.printAllReports('/PrintReports/Reports?summaryID=' + SummaryID) }\">Print</a></td>\n" + " <!-- export name:\"AssignStudyTh\" -->\n" + " <th data-fieldname=\"HasAssigned\">Assign<span data-bind=\"attr: { class: sortField() == 'HasAssigned' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"AssignStudyTd\"-->\n" + " <td><a data-bind=\"visible: !$data.StudyConfirmed, click: function () { $root.assignStudy($data.SummaryID) }\">Assign</a></td>\n" + " <!-- export name:\"FellowNameTh\" -->\n" + " <th data-fieldname=\"FellowPerson\">Fellow Name<span data-bind=\"attr: { class: sortField() == 'FellowPerson' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"FellowNameTd\"-->\n" + " <td data-bind=\"text: $data.FellowPerson && $data.FellowPerson.FullName\"></td>\n" + " <!-- export name:\"AttendingNameTh\" -->\n" + " <th data-fieldname=\"AttendingPerson\">Attending Name<span data-bind=\"attr: { class: sortField() == 'AttendingPerson' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"AttendingNameTd\"-->\n" + " <td data-bind=\"text: $data.AttendingPerson && $data.AttendingPerson.FullName\"></td>\n" + " <!-- export name:\"StudyConfirmedTh\" -->\n" + " <th data-fieldname=\"StudyConfirmed\">Study Confirmed<span data-bind=\"attr: { class: sortField() == 'StudyConfirmed' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"StudyConfirmedTd\"-->\n" + " <td class=\"text-center\"><span class=\"glyphicon glyphicon-ok\" data-bind=\"visible: $data.StudyConfirmed\" /></td>\n" + " <!-- export name:\"StudyExportedTh\" -->\n" + " <th data-fieldname=\"StudyExported\">Study Exported<span data-bind=\"attr: { class: sortField() == 'StudyExported' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"StudyExportedTd\"-->\n" + " <td class=\"text-center\"><span class=\"glyphicon glyphicon-ok\" data-bind=\"visible: $data.StudyExported()\" /></td>\n" + " <!-- export name:\"eMailViewTh\" -->\n" + " <th data-fieldname=\"EmailLogID\">Referral<span data-bind=\"attr: { class: sortField() == 'EmailLogID' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"eMailViewTd\"-->\n" + " <td><a data-bind=\"visible: $data.EmailLogID != 0\" class=\"show-remote-modal\" data-target=\"#myModal\" data-title=\"Referral\" data-fullscreen=\"true\">Print</a></td>\n" + " <!-- export name:\"Flag0Th\" -->\n" + " <th data-fieldname=\"Flag0\">Study Billed<span data-bind=\"attr: { class: sortField() == 'Flag0' ? 'inline-block' : 'hide' }\"></span></th>\n" + " <!-- export name:\"Flag0Td\"-->\n" + " <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>\n" + "<!-- export -->\n" + " <!-- export name:\"Flag0Td\"-->\n" + " <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>\n" + "</body>)"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html