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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
Ugm

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"(?!cm)(?<=Raw Va.ue ;)(?P<v1>.*)Raw Va.ue ;(?P<v2>.*)(?=;Penalty)" test_str = ("1 \n" "\"Simulator is not connected to SimNowlLink ;teports ;'ERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT, ;NOTES: ;IDemoUser ;Ring Rollercoaster 1 ;SCORE: ;26 ;88 ;DATE: 09/04/2020 08:20:36 ;Pay attention to all penalties. You ;can improve drops by following this ;advice: ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;SURGICAL' ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of ;Time to Complete ;Raw Value ;178.0 cm ;129.1 sec. ;50.0 ;50.0 ;Efficiency Subtotat ;Penalties ;Ring Collision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;Instrument-Endoscope Collisions ;Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Vatue ;13.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;2.0 ct. ;1.0 ct. ;Penalty Subtotal ;Overall Score ;pts. ;65.3 ;28.9 ;94 ;-1.3 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-4.0 ;-0.3 ;-6 ;88 ;k. ; \n\n" "2 \n" "\"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;IPtmoUser ;USE R?' ;Ring Rollercoaster 1 ;EXERCISE: ;ATT ÉivlPT ;27 ;DATE: 09/04/2020 ;SCORE BREAKDOWN', ;NOTES: ;Really focus on improving drops by ;following these ;0' handle grasped objectS ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;•j camera clutch to optimize your ;field of view. ;NCH €XERCISE ;INTUITIVE ;SURGICAL v ;SCORE: ;Raw Value ;177.7 cm ;143.4 sec. ;Efficiency hetrics ;Economy bf Åotion ;Time to Complete ;Penalties ;Efficiency Subtotal ;Ring Collision Warning (Yéllow) ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;instrument•Endoscope Collisions ;'Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;14.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.4 sec. ;3.0 ct. ;0.0 ct. ;Max Pts. ;50.0 65.4 ;50.0 23.8 ;89 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-6.0 ;-0.0 ;Penalty Subtotal ;Overall Score ; \n\n" "3 \n" "\"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;28 ;DATE: 09/04/2020 ;SCORE: ;95 ;Good job improving drops! Continue ;to follow this advice to score even ;better: ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of Motion ;Time to Complete ;Efficiency Subtotal ;Penalties ;Ring Cottision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument.lnstrument Collisions ;Instrument -Endoscope Collisions ;Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;149.5 cm ;101.5 sec. ;Raw Value ;8.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;2.0 ct. ;1.0 ct. ;50.0 ;50.0 ;• ;• ;handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL' ;Penalty Subtotal ;Overall Score ;pts. ;70.1 ;38.7 ;too ;-0.8 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-4.0 ;.0.3 ;-5 ;95 ; \n\n" "4 \n" "\"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT: ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;29 ;DATE: 09/04/2020 ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of Motioh ;Time to Complete ;SCORE: ;Raw Value ;170.8 cm ;138.3 sec. ;Really focus on improving drops by ;following these techniques: ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;• camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL r ;Efficiency Subtotat ;Penalties ;Raw Value ;Ring Collision Warning (Yellow) ;, 14.0 ct. ;0.0 ci. ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;0.0 ct. ;Instrument-Endoscope CollisionS ;0.0 ct. ;Endoscope-Environment Collisions ;0.0 ct. ;Excessive Force ;0.0 sec. ;Drops ;5.0 ct. ;Instruments Out of View ;0.0 ct. ;Penalty Subtotal ;Overall Score ;Pts. ;50.0 66.5 ;50.0 25.6 ;92 ;-1.4 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-10.0 ;-0.0 ;-11 ;81 ; \n\n" "5 \n" "\"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPt ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;31 ;DATE: 09/04/2020 08:33:34 ;SCORE BREAKDOWN: ;SCORE: ;85 ;Good job improving drops! , Continue ;to follow this advice to score, even ;better:, ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;• camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL r ;Efficiency Metrics ;Economy of Motion ;Time to Complete ;Raw Value ;164.8 cm ;136.6 sec. ;Efficiency Subtotal. ;Penalties ;Ring Collision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument-instrument Collisions ;Instrument-Endoscope Collisions ;Endoscope-Environment Cottisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;7.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;4.0 ct. ;1.0 ct. ;Penalty Subtotal ;Overall Score ;Pts. ;50.0 67.5 ;50.0 26.2 ;-0.7 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-8.0 ;-0.3 ;85 ; \n\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.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