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 re regex = re.compile(r"\/\*[\s\S]*?\*\/") test_str = ("var ExecutionScript = (function () {\n" " function ExecutionScript() {\n" " }\n" " ExecutionScript.prototype.RemoveSchemes = function (e) {\n" " var _this = this;\n" " debugger;\n" " return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {\n" " var selectedRole, currentSchemes, schemesToRemove, tempSchemes, filteredSchemes, _loop_1, newSchemes, _i, schemesToRemove_1, selectedScheme, _a, _b, scheme_1, newSchemes, _c, newSchemes_1, s;\n" " return __generator(this, function (_d) {\n" " switch (_d.label) {\n" " case 0://test\n" " selectedRole = e.data.Role_Variable.currentItem.Role.currentItem;\n" " currentSchemes = selectedRole.Scheme.value;\n" " schemesToRemove = e.plugins.Schemes_From_Data_Grid.SelectedItems;\n" " tempSchemes = e.data.Temp_Role_Variable.currentItem.Scheme;\n" " _loop_1 = function (selectedScheme) {\n" " var _i, filteredSchemes_1, scheme, _a, newSchemes_2, s;\n" " return __generator(this, function (_b) {\n" " switch (_b.label) {\n" " case 0:\n" " filteredSchemes = currentSchemes.filter(function (scheme) { return scheme.ID !== selectedScheme.ID; });\n" " _i = 0, filteredSchemes_1 = filteredSchemes;\n" " _b.label = 1;/*\n" " * testing multline comment\n" " \n" " */case 1:\n" " if (!(_i < filteredSchemes_1.length)) return [3 /*break*/, 4];\n" " scheme = filteredSchemes_1[_i];/*\n" " * testing multline comment\n" " */\n" " return [4 /*yield*/, tempSchemes.create(1, false, e.data.Temp_Role_Variable.currentItem)];\n" " case 2:\n\n" " /*\n\n" " * testing multline comment\n" " */\n" " newSchemes = _b.sent();\n" " for (_a = 0, newSchemes_2 = newSchemes; _a < newSchemes_2.length; _a++) {\n" " s = newSchemes_2[_a];\n" " s.Active = scheme.Active;\n" " s.Description = scheme.Description;\n" " s.DisplayName = scheme.DisplayName;\n" " s.Name = scheme.Name;\n" " s.Role = scheme.Role;\n" " s.SchemeId = scheme.SchemeId;\n" " }\n" " debugger;\n" " tempSchemes.addItems(newSchemes);\n" " _b.label = 3;\n" " case 3://\n" " _i++;\n" " return [3 /*break*/, 1];\n" " case 4: return [2 /*return*/];\n" " }\n" " });\n" " };//\n" " _i = 0, schemesToRemove_1 = schemesToRemove;\n" " _d.label = 1;\n" " case 1:\n" " if (!(_i < schemesToRemove_1.length)) return [3 /*break*/, 4];\n" " selectedScheme = schemesToRemove_1[_i];\n" " return [5 /*yield**/, _loop_1(selectedScheme)];\n" " case 2:\n" " _d.sent();\n" " _d.label = 3;\n" " case 3:\n" " _i++;\n" " return [3 /*break*/, 1];\n" " case 4:\n" " // }\n" " selectedRole.Scheme.clear();\n" " _a = 0, _b = tempSchemes.value;\n" " _d.label = 5;\n" " case 5:\n" " if (!(_a < _b.length)) return [3 /*break*/, 8];\n" " scheme_1 = _b[_a];\n" " return [4 /*yield*/, selectedRole.Scheme.create(1, false, e.data.Role_Variable.currentItem)];\n" " case 6:\n" " newSchemes = _d.sent();\n" " for (_c = 0, newSchemes_1 = newSchemes; _c < newSchemes_1.length; _c++) {\n" " s = newSchemes_1[_c];\n" " s.Active = scheme_1.Active;\n" " s.Description = scheme_1.Description;\n" " s.DisplayName = scheme_1.DisplayName;\n" " s.Name = scheme_1.Name;\n" " s.Role = scheme_1.Role;\n" " s.SchemeId = scheme_1.SchemeId;\n" " }\n" " selectedRole.Scheme.addItems(newSchemes);\n" " _d.label = 7;\n" " case 7:\n" " _a++;\n" " return [3 /*break*/, 5];\n" " case 8:\n" " e.data.Role_Variable.currentItem;\n" " selectedRole.ConfiguredStatus = 'Complete';\n" " resolve();\n" " return [2 /*return*/];\n" " }\n" " });\n" " }); });\n" " };\n" " ExecutionScript.prototype.S_On_Previous = function (e) {\n" " e.data.currentUser.currentItem.Role.clear();\n" " };\n" " return ExecutionScript;\n" "}());") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html