Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
s

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"(?=.*\{myVariable1\})(?=.*<html>)(?!.*<script>)" test_str = ("Recycle Bin <scrippt>\n" "Assigned to me 18 work items (1 selected)\n" "ResultsEditorCharts Work item paneBottom\n" "Save query\n" "Column options {myVariable1}\n" "Filter\n" "IDWork Item TypeTitleStateRemaining WorkSeverityCreated Date705801Bug Ipad Tablet_PM Planning Labor Grid: Show Cost/Billing dropdown menu is overlapped by Plan Settings menu in PM workspace >> Planning Labor gridCommitted 38/24/2016 11:49:02 PM705969Bug Android Tablet_PM Planning Labor Grid: Columns displayed in Labor middle grid are overlappingCommitted 38/25/2016 4:56:55 AM705973Bug Android Tablet_PM Planning Labor Grid: Available Columns and Selected Columns grids are not displayed in Labor Grid SettingsCommitted 38/25/2016 5:08:06 AM712031Bug Column settings do not use the correct defaultsCommitted 39/14/2016 12:22:09 PM716142Bug Ipad Tablet_PM Plan/Project mode: List of Projects are not displayed properly in Project Result list dropdown menuCommitted 39/28/2016 2:06:17 AM707226Task Dev: Client - Remove Project Settings option and move individual settings to other placesDone 8/30/2016 4<html>35:35 PM619943Task Dev: Client - Actions popup menuDone 7/1/2016 2:03:11 PM693953Task dev:fix options above grid (PBI 612771)Done 7/26/2016 1:36:11 PM696198Task Dev: Changes to grid column selection dialog to support cost and billing views.Done 8/1/2016 1:37:43 PM699509Bug # selections above grid doesnt appear when paging is appliedIn Development 38/9/2016 12:46:11 PM699660Bug # selection doesn't show when \"select All\" checkbox is disabledIn Development ") matches = re.search(regex, test_str, re.DOTALL) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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