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

r"
"
g

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"@Test\s*\((?P<params>[^@\n]*)\)\s+(@\w+\s*\([^@\n]*\s*)*@CitrusTest\((?P<name>[^@\n]*)\)((?!(public|private|protected)).*\n\s*)+(public|private|protected)\s+(?P<return_type>\w+)\s+(?P<method>[\w-]+)\s*\(.*\)\s*{\s*description\w*\(\w*\"".*:\s*(?P<NEs>[\w-]+\s+(\([\w-]+\))?(\s*,\s+[\w-]+)*)\s*\""\s*\)"; string input = @"@Test(enabled=true, groups = { ""set_6"", ""set_6.producction"", ""set_6.cdma"", ""aaa"", ""aaa.activates"" }) @CitrusTest(name = ""AAA - CDMA Activate non-existing subscriber"") public void AAA_CDMA_Activate_NonExisting_Subscriber(){ description(""NEs: AAASL1 (AAA_STG1_HTTP), MBREQ1, MBSYNCREQ1, UISYNCREQ1, MBAAARSP""); /* *********************************** TEST DATA ************************************ */ variable(""NEName"", ""AAASL1""); variable(""NECategory"", ""AAAServer""); variable(""MEID"", ""${MEID}""); variable(""MEID2"", ""${MEID}""); variable(""MDN"", ""${MDN_5}""); variable(""MIN"", ""${MIN_5}""); variable(""CorrelationHandle"", ""${0063_CorrelationHandle}""); /* *********************************************************************************** */ sendBackEndRequest(request.CDMA_DELETE); sendBackEndRequest(request.CDMA_ACTIVATE); applyBehavior(new SendVerify(request.PSB_VERIFY, ""verifySoapClient"")); receive(action -> action.endpoint(""verifySoapClient"") .schemaValidation(false) .validateNamespace(""vs"", ""http://www.verizonwireless.com/mtas/schema/VerifySubscriber"") .validateNamespace(""res"", ""http://www.verizonwireless.com/mtas/schema/Response"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:NetworkElementCode"", ""${NEName}"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:Status/vs:Code"", ""FOUND"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='meidHex']/vs:Value"", ""@equalsIgnoreCase('${MEID}')@"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='DMU_KEY_STATE']/vs:Value"", ""update-keys"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='ServiceIndicators']/vs:Value"", ""MNAI-DUN,IP_POOL_ID-General_FES"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='domain']/vs:Value"", ""vzw3g.com"")); sendBackEndRequest(request.CDMA_DELETE); } @Test(enabled=true, groups = { ""set_6"", ""aaa"", ""aaa.deletes"" }) @CitrusTest(name = ""AAA - CDMA Delete existing subscriber"") public void AAA_CDMA_Delete_Existing_Subscriber(){ description(""NEs: AAASL1 (AAA_STG1_HTTP), MBREQ1, MBSYNCREQ1, UISYNCREQ1, MBAAARSP""); /* *********************************** TEST DATA ************************************ */ variable(""NEName"", ""AAASL1""); variable(""NECategory"", ""AAAServer""); variable(""MEID"", ""${MEID}""); variable(""MEID2"", ""${MEID}""); variable(""MDN"", ""${MDN_5}""); variable(""MIN"", ""${MIN_5}""); variable(""ICCID"", ""${0063_ICCID}""); variable(""IMSI_VZW"", ""${0063_IMSI_VZW}""); variable(""IMSI_VOD"", ""${0063_IMSI_VOD}""); variable(""EUIMID"", ""${0063_EUIMID}""); variable(""RateCenter"", ""${RateCenter}""); variable(""CorrelationHandle"", ""${0063_CorrelationHandle}""); /* *********************************************************************************** */ sendBackEndRequest(request.CDMA_DELETE); sendBackEndRequest(request.CDMA_ACTIVATE); applyBehavior(new SendVerify(request.PSB_VERIFY, ""verifySoapClient"")); receive(action -> action.endpoint(""verifySoapClient"") .schemaValidation(false) .validateNamespace(""vs"", ""http://www.verizonwireless.com/mtas/schema/VerifySubscriber"") .validateNamespace(""res"", ""http://www.verizonwireless.com/mtas/schema/Response"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:NetworkElementCode"", ""${NEName}"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:Status/vs:Code"", ""FOUND"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='meidHex']/vs:Value"", ""@equalsIgnoreCase('${MEID}')@"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='DMU_KEY_STATE']/vs:Value"", ""update-keys"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='ServiceIndicators']/vs:Value"", ""MNAI-DUN,IP_POOL_ID-General_FES"") .validate(""//vs:NetworkElementAttributes/vs:NetworkElementParameters[vs:Name='domain']/vs:Value"", ""vzw3g.com"")); sendBackEndRequest(request.CDMA_DELETE); applyBehavior(new SendVerify(request.PSB_VERIFY, ""verifySoapClient"")); receive(action -> action.endpoint(""verifySoapClient"") .schemaValidation(false) .validateNamespace(""vs"", ""http://www.verizonwireless.com/mtas/schema/VerifySubscriber"") .validateNamespace(""res"", ""http://www.verizonwireless.com/mtas/schema/Response"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:NetworkElementCode"", ""${NEName}"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:Status/vs:Code"", ""NOTFOUND"") .validate(""//vs:VerifyResponse/vs:VerifyResponseContent/vs:NeVerifyResults/vs:Status/vs:Description"", ""Subscriber not found"")); }"; foreach (Match m in Regex.Matches(input, pattern)) { 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