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 = @"([\.#,A-z0-9-_]*)[\s]*:[\s]*([#%A-z0-9-\s''\""\"",.\/\\\(;=:+\)]*);"; string input = @" background-image: url(data:image/svg+xml base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSI1MHB4IiBoZWlnaHQ9IjEzMnB4IiB2aWV3Qm94PSIwIDAgNTAgMTMyIiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjwhLS1HZW5lcmF0b3I6IFNrZXRjaCA1MC4yICg1NTA0NykgLSBodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2gtLT48dGl0bGU+UGF0aCA1PC90aXRsZT48ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz48ZyBpZD0iSG9tZS1wYWdlIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48ZyBpZD0iMjAxOC0wMy0yOF9faG9tZV9fZGVza3RvcCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE0NzYuMDAwMDAwLCAtNDM2OS4wMDAwMDApIiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iMyI+PGcgaWQ9Ikdyb3VwLTMwLUNvcHkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDExMDQuMDAwMDAwLCA0MzI1Ljg1MzQ4MikiPjxwb2x5bGluZSBpZD0iUGF0aC01IiBwb2ludHM9IjM3My4zNzY3MDEgNDQuNzExMjE4OSA0MTkuMjc4NDg3IDExMC40NzkwMyAzNzMuMzc2NzAxIDE3My45MjIwNzMiLz48L2c+PC9nPjwvZz48L3N2Zz4=); .sauce .c-donate-hero { max-width: 130rem; max-inline-size: 130rem; background-image: url(/homepage-9df4b/static/hero-2883d5a72882170fcfabc811b4a46b3b.jpg); background-position: top left 3rem; background-repeat: no-repeat; background-size: 75% auto; margin: 0 auto; padding-top: 70vw; padding-bottom: 5.6rem; -webkit-padding-after: 5.6rem; padding-block-end:5.6rem;} "; 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