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
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

/
/
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(S3C|S2C|S1C|PO3|PO2|PO1|CPO|SCPO|MCPO|SMCPO|ENS|LTJG|LTSG|LT|LCDR|CAPTJG|CAPTSG|CDR|CDRE|CDRE\(F\)|RADM|VADM|ADM|FADM|AotF|Bosun|BT3|BT2|BT1|BM3|BM2|BM1|CBM|SCBM|MCBM|SMCBM|MAA3|MAA2|MAA1|MAM3|MAM2|MAM1|CMAA|SCMAA|MCMAA|SMCMAA|OPS3|OPS2|OPS1|OPM3|OPM2|OPM1|COPM|SCOPM|MCOP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CDSM|SMCDSM|ET3|ET2|ET1|EM3|EM2|EM1|CEM|SCEM|MCEM|SMCEM|CT3|CT2|CT1|CM3|CM2|CM1|CCM|SCMC|MCCM|SMCCM|ST3|ST2|ST1|SM3|SM2|SM1|CSM|SCSM|MCSM|SMCSM|HM3|HM2|HM1|HMP3|HMP2|HMP1|CHM|SCHM|MCHM|SMCHM|PS3|PS2|PS1|PM3|PM2|PM1|CPM|SCPM|MCPM|SMCPM|COX3|COX2|COX1|CXP3|CXP2|CXP1|CCOX|SCCOX|MCCOX|SMCCOX|CR3|CR2|CR1|CRP3|CRP2|CRP1|CCR|SCCR|MCCR|SMCCR|SBA3|SBA2|SBA1|SBP3|SBP2|SBP1|CSBA|SCSBA|MCSBA|SMCSBA|PVT|PFC|LCPL|CPL|PSGT|SSGT|MSGT|1SGT|SGTMAJ|RSGTMAJ|CSGTMAJ|2LT|1LT|CPT|MAJ|LTCOL|COL|BRGEN|MAJGEN|LTGEN|GEN|FMSHL|MSHL|MotA|MotC|WO|WO2|WO1|CWO|SCWO|SCWO|MCWO|SMCWO|GEFR|OGEFR|HGEFR|MT|OMT|B|OB|SB|OSB|OSBDF|MCPON|LDS|OLDS|KL|KK|FK|KDS|FADM|GADM)"; string input = @""; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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