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

/
/
gmi

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?:""?[a-z0-9_\-]{0,256}(?:key|secret|token)[a-z0-9_\-]{0,256}""?\s{0,10}(?::|=)\s{0,10}\""?(?!null|true|false)([a-z0-9+_:\.\-\/]{1,1024})|""Authorization"":""[a-z0-9+:_\-\/]{1,1024}\s(.{1,1024}?(?<!\\)(?="")))"; string input = @"{""secret"":""asdfffasdf"",""headers"":{""uri_1"":""https://www.api.example.com/api/?count=433&apiKey=DD238B9E4369248330EFBB58D6B1431AFB03C8E1D&debug=true"",""uri_2"":""https://www.api.example.com/api/?secret=5ZQD9jhp51qVE5199xU4zj2X2wSPGwNpDub2CiSJO3i"",""uri_3"":""https://www.api.example.com/api/?token=CE362359AAFCB1F8C5BAF4692FD67C18&debug=true"",""uri_4"":""https://www.api.example.com/api/?secret_token=4DA9155E26A75C6D83E208FF518EAFE4&debug=true"",""uri_5"":""https://www.api.example.com/api/?count=433&key=NeRPfka6TETPfHvNoLP4WPBxhhsrOzOh9HyC&debug=true"",""uri_6"":""https://www.api.example.com/api/?apitoken=jq3PGKQDhKjJVo33hRVPK36q0r9-asdf_asdf"",""uri_7"":""https://www.api.example.com/api/?api_key=7119971F47DE25C366F9AB506A1BFD&debug=true"",""uri_8"":""https://www.api.example.com/api/?secret-key=93326A9B41C3DF94BED6E4C9DC524A4F6"",""uri_9"":""https://www.api.example.com/api/?client_secret=6C844DE60C4104936541D4EAB32404DA&debug=true"",""uri_10"":""https://www.api.example.com/api/?count=433&list=daisy&test=true&api_token=lYb6y4GYvFjmW0F8bGAXtcogmkRGa3hkgph530&debug=true"",""uri_11"":""https://www.api.example.com/api/?count=433&api_secret=lYb6y4GYvFjmW0F8bGAXtcogmkRGa3hkgph530&debug=true"",""uri_12"":""https://www.api.example.com/api/?token-pin=8433"",""uri_13"":""https://www.api.example.com/api/?key=4343"",""uri_14"":""https://www.api.example.com/api/?secret-pin=32211190332933"",""auth_0"":{""Authorization"":""Digest username=username, asfsfsf=\""dsffadf\"",\nasfsfsf=\""dsffadf\"",\nasfsfsf=\""dsffadf\"",\nasdfsf=asdfsdf""},""auth_1"":{""Authorization"":""Bearer dasd/4rV4MjOdjA3pu9rJ5qc9RKuCoAO8UaxuWUGXUtuzRJKdRTvKMVe3dJ9FN1SyF9n==""},""auth_2"":{""Authorization"":""App D4D0BB1B2F12B5E97405C764CA45F""},""auth_3"":{""Authorization"":""IPSO dasd+F51B63334AD3520894712D15D8F1105ED3DD""},""auth_4"":{""Authorization"":""Key hJdilwrzM9616MJsDGBiK4qjeJFYB0zmHPxYNUrn8D54ycAN7gwedqHt0UiCWTb""},""auth_5"":{""Authorization"":""Digest username=username, oauth=\""hhasjjjd+ddad\"",\nnonce=\""dsffadf\"",\nhash=\""ef05bc-89c2\"",\nclient=myapp""},""auth_6"":{""Authorization"":""Digest username=\""6551156d‑569c‑4b7d‑945f‑310ff10943c5\"", realm=\""bob@contoso.com\"", qop=auth, algorithm=MD5-sess, uri=\""sip:bob@contoso.com;gruu;opaque=app:conf:focus:id:854T0R7G\"", nonce=\""h8A4ZW22ygGZozIIGZcb43waVMEM6Gq\"", nc=1, cnonce=\""\"", opaque=\""0C1D4536\"", response=\""b4543cd4d6a923b4ab4fd4583af48f0e\""},""auth_7"":{""Authorization"":""Digest username=\""6551156d‑569c‑4b7d‑945f‑310ff10943c5\"",\n realm=\""bob@contoso.com\"",\n qop=auth,\n algorithm=MD5-sess,\n uri=\""sip:bob@contoso.com;gruu;opaque=app:conf:focus:id:854T0R7G\"",\n nonce=\""h8A4ZW22ygGZozIIGZcb43waVMEM6Gq\"",\n nc=1, cnonce=\""\"",\n opaque=\""0C1D4536\"",\n response=\""b4543cd4d6a923b4ab4fd4583af48f0e\""},""apiId"":null,""apiId_2"":null,""apiKey4"":12345689994,""apiKey5"":""123344555"",apiKey"":null,""apiKey2"":null,""apiKey3"":""null""},""multiValueHeaders"":{""Accept"":[""*/*""],""Accept-Encoding"":[""gzip, deflate, br""],""Cache-Control"":[""no-cache""],""Host"":[""myapi.api.example.com""],""Postman-Token"":[""86071fc6-35da-4ff5-8eb5-d44ce06e3eed""],""User-Agent"":[""PostmanRuntime/7.31.1""],""X-Amzn-Trace-Id"":[""Root=1-6428887b-15fa842f16c1eeaf5d812345""],""X-Forwarded-For"":[""10.61.41.39""],""X-Forwarded-Port"":[""443""],""X-Forwarded-Proto"":[""https""],""Client-Secret"":[""451234567890123456"",""90123456789012345"",""e3bc8a2051bae92cc32"",8123456789012345678,""ed1234567890ca1234""],""Client-Token"":[""awbu+d4Tey28-32ntRW3X"",82340514553298753123456,""hw_538291-ec0a91-123456""]}} "; RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase; 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