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

/
/
gim

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\bbb-([\w\.]+(?::.+)?)=\""([\w\.:]+?)\""\s?"; string input = @"<div class=""theme-black"" style=""padding: 20px;background-color: #fff;""> <input type=""text"" class=""text"" bb-model=""color:keyup"" bb-change=""handleChange1"" value=""{{color}}"" /> <input type=""text"" class=""text"" bb-model=""color:keyup"" bb-change=""handleChange1"" value=""{{color}}"" /> <input type=""text"" class=""text"" bb-model=""args.color:keyup"" value=""{{args.color}}"" /> <input type=""text"" class=""text"" bb-model=""color1:keyup"" value=""{{color1}}"" /> <input type=""text"" class=""text"" bb-model=""args.color1:keyup"" value=""{{args.color1}}"" /> <textarea bb-model=""color:keyup"">{{color}}</textarea> <br> <input type=""button"" value=""值1(#999)"" bb-click=""submit1""> <input type=""button"" value=""值1(#999)"" bb-click=""submit1""> <input type=""button"" value=""值2(#ff5241)"" bb-click=""submit2""> <div class=""result1 "" bb-watch=""color:style:html"" bb-change=""handleChange"" style=""color: {{color}};"">{{color}}</div> <div class=""result2 "" bb-watch=""args.color:style:html"" style=""color: {{args.color}};"">{{args.color}}</div> <input type=""button"" value=""dom替换3(#999)"" bb-click=""submit3""> <input type=""button"" value=""dom替换4(#ff5241)"" bb-click=""submit4""> <div class=""result3 "" bb-watch=""color1:style:html"" style=""color: {{color1}};"">{{color1}}</div> <div class=""result4 "" bb-watch=""args.color1:style:html"" style=""color: {{args.color1}};"">{{args.color1}}</div> <br> <input type=""button"" value=""模拟组件传入数据(_reset)"" bb-click:enter=""submit5""> <div class=""all1"" bb-watch=""color:style:html"" style=""color: {{color}};"">{{color}}</div> <div class=""all2"" bb-watch=""color1:style:html"" style=""color: {{color1}};"">{{color1}}</div> <div class=""all3"" bb-watch=""args.color:style:html"" style=""color: {{args.color}};"">{{args.color}}</div> <div class=""all4"" bb-watch=""args.color1:style:html"" style=""color: {{args.color1}};"">{{args.color1}}</div> <div class=""all5"" bb-watch=""args.color:style,args.color1:html"" style=""color: {{args.color}};"">{{args.color1}}</div> <input type=""button"" bb-click=""tab1"" value=""切换(00)"" class=""abutton faiButton faiButton-hover"" style=""margin-top:5px;"" /> <input type=""button"" bb-click=""tab2"" value=""切换(01)"" class=""abutton faiButton faiButton-hover"" style=""margin-top:5px;"" /> <div bb-watch=""tab:style"" style=""display: {{#compare tab '===' '00'}}block;{{else}}none;{{/compare}}"">00</div> <div bb-watch=""tab:style"" style=""display: {{#compare tab '===' '01'}}block;{{else}}none;{{/compare}}"">01</div> </div>"; RegexOptions options = RegexOptions.IgnoreCase | 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