Regular Expressions 101

Save & Share

  • Regex Version: ver. 24
  • 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
No Match

r"
"

Test String

Substitution

Processing...

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"! Global keywords\n\n(.*?)(?=\n\s*\n)"; string substitution = @""; string input = @" !************************************************************************************** ! Generated with OLGA version 2017.2.0 !************************************************************************************** !************************************************************************************** ! Global keywords !************************************************************************************** OPTIONS FLOWMODEL=OLGAHD CASE AUTHOR=Schlumberger, PROJECT=OLGA, TITLE=""Basic Case"" FILES PVTFILE=./3phase.tab INTEGRATION ENDTIME=60 M, MAXDT=5 s, MINDT=0.01 s, STARTTIME=0 s, DTSTART=0.01 s OUTPUT DTOUT=1 h PROFILE DTPLOT=5 M TREND DTPLOT=15 s TRENDDATA VARIABLE=(VOLGBL, HT, GTSOUR) !************************************************************************************** ! Library keywords !************************************************************************************** WALL LABEL=""WALL-1"", THICKNESS=(0.009, 0.02, 0.02) m, MATERIAL=(""MATER-1"", ""MATER-2"", \ ""MATER-2"") WALL LABEL=""WALL-2"", THICKNESS=(0.0075, 0.02, 0.02) m, MATERIAL=(""MATER-1"", ""MATER-2"", \ ""MATER-2"") MATERIAL LABEL=""MATER-1"", CAPACITY=500 J/kg-C, CONDUCTIVITY=50 W/m-C, DENSITY=7850 kg/m3 MATERIAL LABEL=""MATER-2"", CAPACITY=880 J/kg-C, CONDUCTIVITY=1 W/m-C, DENSITY=2500 kg/m3 !************************************************************************************** ! Network Component !************************************************************************************** NETWORKCOMPONENT TYPE=FLOWPATH, TAG=FP_PIPELINE PARAMETERS LABEL=PIPELINE GEOMETRY LABEL=""GEOM-1"" PIPE ROUGHNESS=5E-05 m, LABEL=""PIPE-1"", WALL=""WALL-1"", NSEGMENT=10, LENGTH=400 m, \ ELEVATION=10 m, DIAMETER=0.12 m BRANCH FLUID=Fluid1 HEATTRANSFER LABEL=""HEATTRANS-1"", TAMBIENT=6 C, HAMBIENT=6.5 W/M2-C SOURCE LABEL=""SOURCE-1"", TIME=(0, 10, 20, 30, 40) M, PIPE=""PIPE-1"", SECTION=1, \ TEMPERATURE=(62, 62, 62, 62, 62) C, MASSFLOW=(18, 18, 9, 9, 18) KG/S TRENDDATA PIPE=""PIPE-1"", SECTION=1, VARIABLE=(HOL, HOLWT, ID, PT, Q2, TM, TU) TRENDDATA VARIABLE=(OILC, WATC, GASC, OILCFR, WATCFR, GASCFR) PROFILEDATA VARIABLE=(HOL, PT, TM, QLT, QG, Q2, ID, QLTWT) SERVERDATA PIPE=""PIPE-1"", SECTION=1, VARIABLE=(HOL, HOLWT, PT, TM) SERVERDATA VARIABLE=(HOL, HOLWT, PT, TM) SERVERDATA VARIABLE=(QLT, QG, QLTWT, ID) TRENDDATA PIPE=""PIPE-1"", SECTION=11, VARIABLE=(QT, QG, QLT, QLTHL, QLTWT, QGST, \ QOST, QWTST, GT, GG, GL) ENDNETWORKCOMPONENT !************************************************************************************** ! Network Component !************************************************************************************** NETWORKCOMPONENT TYPE=NODE, TAG=NODE_INLET PARAMETERS LABEL=INLET, TYPE=CLOSED ENDNETWORKCOMPONENT !************************************************************************************** ! Network Component !************************************************************************************** NETWORKCOMPONENT TYPE=NODE, TAG=NODE_OUTLET PARAMETERS LABEL=OUTLET, TYPE=PRESSURE, TEMPERATURE=22 C, PRESSURE=5000000 Pa, \ FLUID=Fluid1 ENDNETWORKCOMPONENT !************************************************************************************** ! Connections !************************************************************************************** CONNECTION TERMINALS = (FP_PIPELINE INLET, NODE_INLET FLOWTERM_1) CONNECTION TERMINALS = (FP_PIPELINE OUTLET, NODE_OUTLET FLOWTERM_1) ENDCASE "; Regex regex = new Regex(pattern); string result = regex.Replace(input, substitution, 1); } }

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