Regular Expressions 101

Save & Manage Regex

  • Current Version: 3
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(<(a|link|script|div|iframe)(?:\s[^>]*[\s""']|\s)(?:(data-settings|href|data-src)(?!\s*=\s*[\\]?&quot\b))=([\""\']??))([^\4]*)(\4[^>]*>)"; string input = @"<iframe hcb-fetch-image-from=""&lt;iframe src=&quot;https://player.vimeo.com/video/33234? dnt=1&quot; h=4725157e&quot; width=&quot;640&quot; height=&quot;360&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; fullscreen; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;"" class=""elementor-video-iframe"" allowfullscreen title=""vimeo Video Player"" data-lazy-load=""https://player.vimeo.com/video/651646452?color&amp;autopause=0&amp;loop=0&amp;muted=0&amp;title=1&amp;portrait=1&amp;byline=1#t=""></iframe> This is an regex built on top of <a href='https://www.the-art-of-web.com/php/parse-links/' class=""test""> This is an regex built on top of <a href='https://www.the-art-of-web.com/php/parse-links/' class=""test""> This is an regex built on top of <a test=""href='https://www.the-art-of-web.com/php/parse-links/' class=""test""> This is an regex built on top of <a test="" not-matching-href='https://www.the-art-of-web.com/php/parse-links/' class=""test""> This is link <link rel=""stylesheet"" href=""http://google.com""> This is script <script src=""http://devowl.io""> This is script <script data-src=""http://devowl.io""> This is script <script wup src=""http://devowl.io""> Another line <link data-src=""{&quot;youtube_url&quot;:&quot;https:\/\/www.youtube.com\/watch&quot;}"" another=""attribute"" /> <div class=""elementor-element elementor-element-bc17ee6 elementor-aspect-ratio-169 elementor-widget elementor-widget-video"" data-id=""bc17ee6"" data-element_type=""widget"" data-settings=""{&quot;youtube_url&quot;:&quot;https:\/\/www.youtube.com\/watch?v=XHOmBV4js_E&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;,&quot;aspect_ratio&quot;:&quot;169&quot;}"" data-widget_type=""video.default""> <link hcb-fetch-image-from=""&lt;a href=&quot;https://player.vimeo.com/video/33234?screen;picture-in-picture&quot;&gt;&lt;/a&gt;"" href=""https://example.com/link.css"" /> <div data-markers=""[{&quot;title&quot;:&quot;Stylish remodeled room&quot;,&quot;latitude&quot;:40,&quot;longitude&quot;:-73,&quot;content&quot;:&quot;&lt;div class=\&quot;hp-listing hp-listing--map-block\&quot;&gt;&lt;h5 class=\&quot;hp-listing__title\&quot;&gt;&lt;a href=\&quot;https:\/\/example.de\/listing\/stylish-remodeled-room\/\&quot;&gt;Stylish remodeled room&lt;\/a&gt;\n&lt;\/h5&gt;&lt;\/div&gt;&quot;}]"" class=""hp-listing__map hp-listing__map widget hp-map"" data-max-zoom=""18"" data-component=""map"" href=""test""></div> <div class=""wpforms-container wpforms-container-full"" id=""wpforms-1081""><form id=""wpforms-form-1081"" class=""wpforms-validate wpforms-form"" data-formid=""1081"" method=""post"" enctype=""multipart/form-data"" action=""/wpforms/"" data-token=""43285f0e3d425addb1b108bd61d3dee9""><noscript class=""wpforms-error-noscript"">Please enable JavaScript in your browser to complete this form.</noscript><div class=""wpforms-field-container""><div id=""wpforms-1081-field_0-container"" class=""wpforms-field wpforms-field-name"" data-field-id=""0""><label class=""wpforms-field-label"" for=""wpforms-1081-field_0"">Name <span class=""wpforms-required-label"">*</span></label><div class=""wpforms-field-row wpforms-field-medium""><div class=""wpforms-field-row-block wpforms-first wpforms-one-half""><input type=""text"" id=""wpforms-1081-field_0"" class=""wpforms-field-name-first wpforms-field-required"" name=""wpforms[fields][0][first]"" required><label for=""wpforms-1081-field_0"" class=""wpforms-field-sublabel after "">First</label></div><div class=""wpforms-field-row-block wpforms-one-half""><input type=""text"" id=""wpforms-1081-field_0-last"" class=""wpforms-field-name-last wpforms-field-required"" name=""wpforms[fields][0][last]"" required><label for=""wpforms-1081-field_0-last"" class=""wpforms-field-sublabel after "">Last</label></div></div></div><div id=""wpforms-1081-field_1-container"" class=""wpforms-field wpforms-field-email"" data-field-id=""1""><label class=""wpforms-field-label"" for=""wpforms-1081-field_1"">Email <span class=""wpforms-required-label"">*</span></label><input type=""email"" id=""wpforms-1081-field_1"" class=""wpforms-field-medium wpforms-field-required"" name=""wpforms[fields][1]"" required></div><div id=""wpforms-1081-field_2-container"" class=""wpforms-field wpforms-field-textarea"" data-field-id=""2""><label class=""wpforms-field-label"" for=""wpforms-1081-field_2"">Comment or Message <span class=""wpforms-required-label"">*</span></label><textarea id=""wpforms-1081-field_2"" class=""wpforms-field-medium wpforms-field-required"" name=""wpforms[fields][2]"" required></textarea></div></div><div class=""wpforms-submit-container"" ><input type=""hidden"" name=""wpforms[id]"" value=""1081""><input type=""hidden"" name=""wpforms[author]"" value=""1""><input type=""hidden"" name=""wpforms[post_id]"" value=""1082""><button type=""submit"" name=""wpforms[submit]"" class=""wpforms-submit "" id=""wpforms-submit-1081"" value=""wpforms-submit"" aria-live=""assertive"" data-alt-text=""Sending..."" data-submit-text=""Submit"">Submit</button></div></form></div> <!-- .wpforms-container --> </div><!-- .entry-content --> <footer class=""entry-meta""> <span class=""edit-link""><a class=""post-edit-link"" href=""http://gitlab-ci-runner-3.owlsrv.de:10000/wp-admin/post.php?post=1082&#038;action=edit"">Edit</a></span> </footer><!-- .entry-meta --> </article><!-- #post-1082 -->"; RegexOptions options = RegexOptions.Singleline | 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