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 = @"(?:(?# #json->start)(?:(?# #array->start)\[\s*(?:(?# #element-in-array->start)(?:(?# #object->start){\s*(?:(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?# #key:value->end))(?:\s*,\s*(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?# #key:value->end)))*)?\s*}(?# #object->end))|(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end))(?# #element-in-array->end))(?:\s*,\s*(?:(?# #element-in-array->start)(?:(?# #object->start){\s*(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?# #key:value->end))(?:\s*,\s*(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?# #key:value->end)))*\s*}(?# #object->end))|(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end))(?# #element-in-array->end)))*\s*\]|\[\s*\](?# #array->end))|(?:(?# #object->start){\s*(?:(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?# #key:value->end))(?:\s*,\s*(?:(?# #key:value->start)(?:(?:(?# #key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?# #value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?##key:value->end)))*)?\s*}(?# #object->end))|(?:(?# #value->start)""(?:\\.|[^\\""]*)*""|(?<=[,:\s\[])[+-]?(?:[1-9]\d*|0)(?:\.\d+)?(?=[\s,\]}])|true|false|null(?#value->end))(?# #json->end))"; string input = @"{ ""code"": 1, ""re"": [ ""B121"" ], ""msg"": null, ""e"": null, ""detailMsg"": null, ""point"": ""com.hshc.hshcwap.modules.secondhand.controller.SecondHandController.queryBrand(SecondHandController.java:270)"", ""pointList"": [ ], ""error"": false, ""success"": true, ""successAndReNN"": true } ------------- true,false , null, +33.640, 055.23,-22.340, ""12\""a\\\\"" ------------- {} ------------ { ""dt"":""LEADSEC_CS_0700R0600B20171127140643"", ""level"":20, ""id"":""152525881"", ""type"":""Alert Log"", ""time"":1585291269424, ""source"":{ ""ip"":""100.100.100.1"", ""port"":50223, ""mac"":""ec-41-18-19-3a-54"" }, ""destination"":{ ""ip"":""20.20.2.4"", ""port"":80, ""mac"":""c8-0c-c8-ef-09-50"" }, ""protocol"":""HTTP"", ""securityid"":""4"", ""attackid"":""1003"", ""subject"":""HTTP_Acunetix11_AWVS11_Content_Web漏洞扫描2"", ""message"":""nic=5;Method=POST;Host=20.20.2.4;URL长度=215;Http协议头长度=875;URL=/cgi-bin/php.cgi?-d allow_url_include=on -d safe_mode=off -d suhosin.simulation=on -d disable_functions=\""\"" -d open_basedir=none -d auto_prepend_file=php:/input -d cgi.force_redirect=0 -d cgi.redirect_status_env=0 -n;访问文件=php.cgi;MsgbodyData=3c 3f 70 68 70 20 65 63 68 6f 28 6d 64 35 28 61 63 75 6e 65 74 69 78 2d 70 68 70 2d 63 67 69 2d 72 63 65 29 29 3b 20 3f 3e;"" } "; 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