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

/
/
gim

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$;-])*"; string input = @"https://web.facebook.com https://google.com https://web.facebook.com/destiney.arkaden/posts/pfbid0jxqYa9Jkfoe9rATYUAcv9FsRnc1NGea2Kz6JxZPHKbe17xjS1akgEk5z6Z4tQTh2l?__cft__%5B0%5D=AZXy-D_E-IEYmmLc13KwLzY8E3AVjhlr1HRlJ1ejqqP1GqpRxK3ntzsoBEdpNopoBqAi_JHZJeZfYatg8ey4vsuU2vTHRjqxurMX6VYuVboZ9yAmDBWWWKdw87M6wai_ovqA-9bXektCQtxpAgNJCp0B&__tn__=%2CO%2CP-R; <div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">Wondering what it takes to study in Europe?</span></span></span></span></div><div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">Join </span></span></span></span><a href=""https://setlinn.com/profile/63cb889363b41c3cd16b37e6"" target=""_blank"" rel=""noopener noreferrer""><span data-slate-node=""element"" data-slate-inline=""true"" data-slate-void=""true"" contenteditable=""false"" data-cy=""mention-Mahtabuzzaman-Rangan"" class=""mentionedUser"" style=""padding: 3px 3px 2px; margin: 0px 1px; vertical-align: baseline; display: inline-block; border-radius: 4px; font-size: 0.9em; box-shadow: none;""><span data-slate-spacer=""true"" style=""height: 0px; color: transparent; outline: currentcolor; position: absolute;""><span data-slate-node=""text""><span data-slate-leaf=""true""><span data-slate-zero-width=""z"" data-slate-length=""21""></span></span></span></span>@Mahtabuzzaman Rangan</span></a><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">as we bring him live on Facebook tomorrow to explain the step-wise processes.</span></span></span></span></div><div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-zero-width=""z"" data-slate-length=""0""></span></span></span></span><a href=""https://setlinn.com/profile/63a042575380303f8d583116"" target=""_blank"" rel=""noopener noreferrer""><span data-slate-node=""element"" data-slate-inline=""true"" data-slate-void=""true"" contenteditable=""false"" data-cy=""mention-Michael-Onwuatuegwu"" class=""mentionedUser"" style=""padding: 3px 3px 2px; margin: 0px 1px; vertical-align: baseline; display: inline-block; border-radius: 4px; font-size: 0.9em; box-shadow: none;""><span data-slate-spacer=""true"" style=""height: 0px; color: transparent; outline: currentcolor; position: absolute;""><span data-slate-node=""text""><span data-slate-leaf=""true""><span data-slate-zero-width=""z"" data-slate-length=""20""></span></span></span></span>@Michael Onwuatuegwu</span></a><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">will be on the session too.</span></span></span></span></div><div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-zero-width=""n"" data-slate-length=""0""><br></span></span></span></span></div><div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">Link to join ⬇️ </span></span></span></span></div><div data-slate-node=""element""><span data-slate-node=""text""><span data-slate-leaf=""true""><span><span data-slate-string=""true"">https://web.facebook.com/destiney.arkaden/posts/pfbid0jxqYa9Jkfoe9rATYUAcv9FsRnc1NGea2Kz6JxZPHKbe17xjS1akgEk5z6Z4tQTh2l?__cft__%5B0%5D=AZXy-D_E-IEYmmLc13KwLzY8E3AVjhlr1HRlJ1ejqqP1GqpRxK3ntzsoBEdpNopoBqAi_JHZJeZfYatg8ey4vsuU2vTHRjqxurMX6VYuVboZ9yAmDBWWWKdw87M6wai_ovqA-9bXektCQtxpAgNJCp0B&amp;__tn__=%2CO%2CP-R</span></span></span></span></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