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 = @"https:\/\/vod-progressive(.*?)\/\d+\.mp4"; string input = @"<!DOCTYPE html> <html lang=""en""> <head> <meta charset=""utf-8""> <meta name=""viewport"" content=""width=device-width,initial-scale=1,user-scalable=yes""> <meta name=""robots"" content=""noindex""> <title>Wagtail Walkthrough from Kalob Taulien on Vimeo</title> <style> body, html, .player, .fallback { overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0; background-color: transparent; } .player.loading { opacity: 0; } </style> <script> !function(){if('PerformanceLongTaskTiming' in window){var g=window.__tti={e:[]}; g.o=new PerformanceObserver(function(l){g.e=g.e.concat(l.getEntries())}); g.o.observe({entryTypes:['longtask']})}}(); </script> <!--[if IE]><script>var cacheBuster = '?' + Math.round((Math.random() * 1000) + new Date().getTime());</script><![endif]--> </head> <body> <div class=""vp-placeholder""> <style> .vp-placeholder, .vp-placeholder-thumb, .vp-placeholder-thumb::before, .vp-placeholder-thumb::after { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .vp-placeholder { visibility: hidden; width: 100%; max-height: 100%; height: calc(1440 / 2560 * 100vw); max-width: calc(2560 / 1440 * 100vh); margin: auto; } .vp-placeholder-carousel { display: none; background-color: #000; position: absolute; left: 0; right: 0; bottom: -60px; height: 60px; } </style> <style> .vp-placeholder-thumb { overflow: hidden; width: 100%; max-height: 100%; margin: auto; } .vp-placeholder-thumb::before, .vp-placeholder-thumb::after { content: ""; display: block; filter: blur(7px); margin: 0; background: url(https://i.vimeocdn.com/video/844533727.jpg?mw=80&q=85) 50% 50% / contain no-repeat; } .vp-placeholder-thumb::before { margin: -30px; } </style> <div class=""vp-placeholder-thumb""></div> <div class=""vp-placeholder-carousel""></div> <script> (function(document) { var placeholder = document.querySelector('.vp-placeholder'); var placeholderThumb = document.querySelector('.vp-placeholder-thumb'); var videoWidth = parseInt('2560'); var videoHeight = parseInt('1440'); var thumb = new Image(); thumb.onload = function() { var videoAspectRatio = videoWidth / videoHeight; var imageAspectRatio = this.width / this.height; if (imageAspectRatio <= 0.95 * videoAspectRatio || imageAspectRatio >= 1.05 * videoAspectRatio) { var rect = placeholder.getBoundingClientRect(); var placeholderWidth = rect.right - rect.left; var placeholderHeight = rect.bottom - rect.top; var viewportWidth = window.innerWidth / placeholderWidth * 100; var viewportHeight = window.innerHeight / placeholderHeight * 100; placeholderThumb.style.height = 'calc(' + this.height + ' / ' + this.width + ' * ' + viewportWidth + 'vw)'; placeholderThumb.style.maxWidth = 'calc(' + this.width + ' / ' + this.height + ' * ' + viewportHeight + 'vh)'; } placeholder.style.visibility = 'visible'; }; thumb.src = ""https://i.vimeocdn.com/video/844533727.jpg?mw=80&q=85""; }(document)); </script> </div> <div id=""player"" class=""player""></div> <script> (function(document, player) { var config = {""cdn_url"":""https://f.vimeocdn.com"",""vimeo_api_url"":""api.vimeo.com"",""request"":{""files"":{""dash"":{""separate_av"":true,""streams"":[{""profile"":174,""quality"":""720p"",""id"":""9e93344a-4f42-4416-98ae-86d8367252b1"",""fps"":30},{""profile"":139,""quality"":""240p"",""id"":""ed879cf2-d41c-4731-9ffb-bead81c71117"",""fps"":30},{""profile"":175,""quality"":""1080p"",""id"":""0d01b0ad-9417-4874-b64a-48d36a7a20c5"",""fps"":30},{""profile"":170,""quality"":""1440p"",""id"":""1d1991ed-568e-4a2d-b9d7-8d32b201234f"",""fps"":30},{""profile"":165,""quality"":""540p"",""id"":""2fea6eb5-d483-403a-bbc3-359c30ab66ac"",""fps"":30},{""profile"":164,""quality"":""360p"",""id"":""614d1bb4-06db-4bce-b685-d1311f7a3ee7"",""fps"":30}],""cdns"":{""akfire_interconnect_quic"":{""url"":""https://142vod-adaptive.akamaized.net/exp=1589889109~acl=%2Fdeab633f-34bf-4c84-b470-b2a4b0b8ab7d%2F%2A~hmac=208ea435082b124c2476c01b5e1d53b92da81381c23b9f514813679800fe12fb/deab633f-34bf-4c84-b470-b2a4b0b8ab7d/sep/video/9e93344a,ed879cf2,0d01b0ad,1d1991ed,2fea6eb5,614d1bb4/master.json?base64_init=1"",""origin"":""gcs"",""avc_url"":""https://142vod-adaptive.akamaized.net/exp=1589889109~acl=%2Fdeab633f-34bf-4c84-b470-b2a4b0b8ab7d%2F%2A~hmac=208ea435082b124c2476c01b5e1d53b92da81381c23b9f514813679800fe12fb/deab633f-34bf-4c84-b470-b2a4b0b8ab7d/sep/video/9e93344a,ed879cf2,0d01b0ad,1d1991ed,2fea6eb5,614d1bb4/master.json?base64_init=1""}},""streams_avc"":[{""profile"":174,""quality"":""720p"",""id"":""9e93344a-4f42-4416-98ae-86d8367252b1"",""fps"":30},{""profile"":139,""quality"":""240p"",""id"":""ed879cf2-d41c-4731-9ffb-bead81c71117"",""fps"":30},{""profile"":175,""quality"":""1080p"",""id"":""0d01b0ad-9417-4874-b64a-48d36a7a20c5"",""fps"":30},{""profile"":170,""quality"":""1440p"",""id"":""1d1991ed-568e-4a2d-b9d7-8d32b201234f"",""fps"":30},{""profile"":165,""quality"":""540p"",""id"":""2fea6eb5-d483-403a-bbc3-359c30ab66ac"",""fps"":30},{""profile"":164,""quality"":""360p"",""id"":""614d1bb4-06db-4bce-b685-d1311f7a3ee7"",""fps"":30}],""default_cdn"":""akfire_interconnect_quic""},""hls"":{""separate_av"":true,""default_cdn"":""akfire_interconnect_quic"",""cdns"":{""akfire_interconnect_quic"":{""url"":""https://142vod-adaptive.akamaized.net/exp=1589889109~acl=%2Fdeab633f-34bf-4c84-b470-b2a4b0b8ab7d%2F%2A~hmac=208ea435082b124c2476c01b5e1d53b92da81381c23b9f514813679800fe12fb/deab633f-34bf-4c84-b470-b2a4b0b8ab7d/sep/video/9e93344a,ed879cf2,0d01b0ad,1d1991ed,2fea6eb5,614d1bb4/master.m3u8"",""origin"":""gcs"",""avc_url"":""https://142vod-adaptive.akamaized.net/exp=1589889109~acl=%2Fdeab633f-34bf-4c84-b470-b2a4b0b8ab7d%2F%2A~hmac=208ea435082b124c2476c01b5e1d53b92da81381c23b9f514813679800fe12fb/deab633f-34bf-4c84-b470-b2a4b0b8ab7d/sep/video/9e93344a,ed879cf2,0d01b0ad,1d1991ed,2fea6eb5,614d1bb4/master.m3u8""}}},""progressive"":[{""profile"":174,""width"":1280,""mime"":""video/mp4"",""fps"":30,""url"":""https://vod-progressive.akamaized.net/exp=1589889109~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1461%2F15%2F382307071%2F1604434871.mp4~hmac=900044ddf9b52605c0352cd20ad5f08f7d2f97ae5f45d880421f694d4765b297/vimeo-prod-skyfire-std-us/01/1461/15/382307071/1604434871.mp4"",""cdn"":""akamai_interconnect"",""quality"":""720p"",""id"":""9e93344a-4f42-4416-98ae-86d8367252b1"",""origin"":""gcs"",""height"":720},{""profile"":139,""width"":426,""mime"":""video/mp4"",""fps"":30,""url"":""https://vod-progressive.akamaized.net/exp=1589889109~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1461%2F15%2F382307071%2F1604434529.mp4~hmac=8662faaba3518283d71337078a6120c5ed2aba5bed806ceac54dc29169db818b/vimeo-prod-skyfire-std-us/01/1461/15/382307071/1604434529.mp4"",""cdn"":""akamai_interconnect"",""quality"":""240p"",""id"":""ed879cf2-d41c-4731-9ffb-bead81c71117"",""origin"":""gcs"",""height"":240},{""profile"":175,""width"":1920,""mime"":""video/mp4"",""fps"":30,""url"":""https://vod-progressive.akamaized.net/exp=1589889109~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1461%2F15%2F382307071%2F1604434874.mp4~hmac=6484316249a942a6258f932f1b24bb8898aeb930b39923e37b8ae37c12333c5a/vimeo-prod-skyfire-std-us/01/1461/15/382307071/1604434874.mp4"",""cdn"":""akamai_interconnect"",""quality"":""1080p"",""id"":""0d01b0ad-9417-4874-b64a-48d36a7a20c5"",""origin"":""gcs"",""height"":1080},{""profile"":165,""width"":960,""mime"":""video/mp4"",""fps"":30,""url"":""https://vod-progressive.akamaized.net/exp=1589889109~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1461%2F15%2F382307071%2F1604434872.mp4~hmac=97c414c4f6400ba4736ae75301847d1125e65ead8b0e16a48d76822684f92e04/vimeo-prod-skyfire-std-us/01/1461/15/382307071/1604434872.mp4"",""cdn"":""akamai_interconnect"",""quality"":""540p"",""id"":""2fea6eb5-d483-403a-bbc3-359c30ab66ac"",""origin"":""gcs"",""height"":540},{""profile"":164,""width"":640,""mime"":""video/mp4"",""fps"":30,""url"":""https://vod-progressive.akamaized.net/exp=1589889109~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1461%2F15%2F382307071%2F1604434166.mp4~hmac=2e72887d140cc5aee1b72903a5e5bcf81ad4a055f1fdccc5225c8c6d9e073111/vimeo-prod-skyfire-std-us/01/1461/15/382307071/1604434166.mp4"",""cdn"":""akamai_interconnect"",""quality"":""360p"",""id"":""614d1bb4-06db-4bce-b685-d1311f7a3ee7"",""origin"":""gcs"",""height"":360}]},""lang"":""en"",""sentry"":{""url"":""https://6f5f8e1cecfa40fb850f578b69fc1705@sentry.io/1297650"",""enabled"":false,""debug_enabled"":true,""debug_intent"":0},""ab_tests"":{""chromecast"":{""track"":false,""data"":{},""group"":false},""cdn_preference"":{""track"":false,""data"":{""city"":""paris"",""country_code"":""FR"",""hls_pref_found"":false,""dash_pref_found"":true},""group"":true},""webvr"":{""track"":false,""data"":{},""group"":false}},""referrer"":""https://learnwagtail.com/wagtail-for-beginners/wagtail-walkthrough/"",""cookie_domain"":"".vimeo.com"",""timestamp"":1589885209,""gc_debug"":{""bucket"":""vimeo-player-debug""},""expires"":3600,""currency"":""EUR"",""session"":""ad275d4641f2c264e5d108c0528a23299e7c91a71589885209"",""cookie"":{""scaling"":1,""volume"":1.0,""quality"":null,""hd"":0,""captions"":null},""build"":{""backend"":""1.17.1"",""js"":""3.20.5""},""urls"":{""barebone_js"":""https://f.vimeocdn.com/p/3.20.5/js/barebone.js"",""test_imp"":""https://fresnel.vimeocdn.com/add/player-test-impression"",""js_base"":""https://f.vimeocdn.com/p/3.20.5/js/"",""fresnel"":""https://fresnel.vimeocdn.com/add/player-stats"",""js"":""https://f.vimeocdn.com/p/3.20.5/js/player.js"",""proxy"":""https://player.vimeo.com/static/proxy.html"",""mux_url"":""https://f.vimeocdn.com/p/external/mux.js"",""fresnel_mimir_inputs_url"":""https://fresnel-events.vimeocdn.com/add/mimir_inputs"",""fresnel_chunk_url"":""https://fresnel-events.vimeocdn.com/add/chunk_downloads"",""three_js"":""https://f.vimeocdn.com/p/external/three.rvimeo.min.js"",""fresnel_manifest_url"":""https://fresnel-events.vimeocdn.com/add/playback_manifest"",""chromeless_css"":""https://f.vimeocdn.com/p/3.20.5/css/chromeless.css"",""vuid_js"":""https://f.vimeocdn.com/js_opt/modules/utils/vuid.min.js"",""chromeless_js"":""https://f.vimeocdn.com/p/3.20.5/js/chromeless.js"",""css"":""https://f.vimeocdn.com/p/3.20.5/css/player.css""},""signature"":""b9ad2e4634497980f7259fc03418cea6"",""flags"":{""dnt"":0,""preload_video"":""metadata_on_hover"",""plays"":1,""partials"":1,""autohide_controls"":0},""country"":""FR"",""file_codecs"":{""hevc"":{""hdr"":[],""sdr"":[]},""av1"":[],""avc"":[""9e93344a-4f42-4416-98ae-86d8367252b1"",""ed879cf2-d41c-4731-9ffb-bead81c71117"",""0d01b0ad-9417-4874-b64a-48d36a7a20c5"",""1d1991ed-568e-4a2d-b9d7-8d32b201234f"",""2fea6eb5-d483-403a-bbc3-359c30ab66ac"",""614d1bb4-06db-4bce-b685-d1311f7a3ee7""]}},""player_url"":""player.vimeo.com"",""video"":{""rating"":{""id"":6},""version"":{""current"":null,""available"":[{""is_current"":1,""id"":96044288,""file_id"":1604433951}]},""height"":1440,""duration"":628,""thumbs"":{""1280"":""https://i.vimeocdn.com/video/844533727_1280.jpg"",""960"":""https://i.vimeocdn.com/video/844533727_960.jpg"",""640"":""https://i.vimeocdn.com/video/844533727_640.jpg"",""base"":""https://i.vimeocdn.com/video/844533727""},""owner"":{""account_type"":""pro"",""name"":""Kalob Taulien"",""img"":""https://i.vimeocdn.com/portrait/29431924_60x60.jpg"",""url"":""https://vimeo.com/codingforeverybody"",""img_2x"":""https://i.vimeocdn.com/portrait/29431924_120x120.jpg"",""id"":46884647},""id"":382307071,""embed_code"":""<iframe title=\""vimeo-player\"" src=\""https://player.vimeo.com/video/382307071\"" width=\""640\"" height=\""360\"" frameborder=\""0\"" allowfullscreen><\/iframe>"",""title"":""Wagtail Walkthrough"",""share_url"":""https://vimeo.com/382307071"",""width"":2560,""embed_permission"":""whitelist"",""fps"":30.0,""spatial"":0,""live_event"":null,""allow_hd"":1,""hd"":1,""lang"":""en-CA"",""default_to_hd"":0,""url"":null,""privacy"":""disable"",""bypass_token"":""eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGlwX2lkIjozODIzMDcwNzEsImV4cCI6MTU4OTg4ODgyMH0.uhpl7JLaotK0zkUJrjCMbAXNscnBaYWxlyoAx5ypsEY"",""unlisted_hash"":null},""user"":{""team_origin_user_id"":0,""liked"":0,""account_type"":""none"",""vimeo_api_client_token"":null,""vimeo_api_interaction_tokens"":null,""team_id"":0,""watch_later"":0,""owner"":0,""id"":0,""mod"":0,""logged_in"":0},""embed"":{""autopause"":1,""playsinline"":1,""settings"":{""fullscreen"":1,""byline"":0,""like"":0,""playbar"":1,""title"":0,""color"":1,""speed"":1,""watch_later"":0,""share"":0,""scaling"":1,""spatial_compass"":0,""collections"":0,""info_on_pause"":0,""portrait"":0,""logo"":0,""embed"":0,""badge"":0,""spatial_label"":0,""volume"":1},""color"":""ffd546"",""texttrack"":"",""on_site"":0,""app_id"":"",""muted"":0,""dnt"":0,""player_id"":"",""api"":null,""editor"":false,""context"":""embed.main"",""time"":0,""outro"":""beginning"",""log_plays"":1,""quality"":null,""transparent"":1,""loop"":0,""autoplay"":0},""view"":1,""vimeo_url"":""vimeo.com""}; if (!config.request) { return; } if (typeof config.request === 'object' && 'error' in config.request) { if ('html' in config.request) { document.documentElement.innerHTML = config.request.html.replace(/&lt;/g, '<').replace(/&gt;/g, '>'); } return; } var isIframe = (function() { try { return window.self !== window.top; } catch (e) { return true; } }()); if (!isIframe && /twitter/i.test(navigator.userAgent) && config.video.url) { window.location = config.video.url; } if (config.request.lang) { document.documentElement.setAttribute('lang', config.request.lang); } var fullscreenSupport = 'exitFullscreen' in document || 'webkitExitFullscreen' in document || 'webkitCancelFullScreen' in document || 'mozCancelFullScreen' in document || 'msExitFullscreen' in document || 'webkitEnterFullScreen' in document.createElement('video'); var inlineSvgSupport = (function() { var div = document.createElement('div'); div.innerHTML = '<svg/>'; return (div.firstChild && div.firstChild.namespaceURI) === 'http://www.w3.org/2000/svg'; }()); var windowsPhone = /MSIE 9/.test(navigator.userAgent) && /Windows Phone/.test(navigator.userAgent); var IE10 = /IE 10/.test(navigator.userAgent); var usePlayer = fullscreenSupport || IE10 || windowsPhone; var firstScript = document.getElementsByTagName('script')[0]; var script = document.createElement('script'); var jsDone = false; var playerObject = false; if (!inlineSvgSupport) { usePlayer = false; } if (!usePlayer) { var placeholder = document.querySelector('.vp-placeholder'); if (placeholder && placeholder.parentNode) { placeholder.parentNode.removeChild(placeholder); } } if (usePlayer) { player.className = 'player loading'; var startTime = new Date().getTime(); script.src = config.request.urls.js; firstScript.parentNode.insertBefore(script, firstScript); script['onreadystatechange' in script ? 'onreadystatechange' : 'onload'] = function() { if (!jsDone && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { jsDone = true; playerObject = new VimeoPlayer(player, config, cssDone || { link: link, startTime: startTime }); } }; var cssDone = false; var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = config.request.urls.css + (typeof cacheBuster === 'undefined' ? '' : cacheBuster); document.getElementsByTagName('head')[0].appendChild(link); link.onload = function() { cssDone = true; }; } else { player.innerHTML = '<div class=""fallback""><iframe title=""vimeo-player"" src=""/video/382307071/fallback?js&amp;referrer=' + encodeURIComponent(config.request.referrer) + '"" frameborder=""0""></iframe></div>'; } if (!config.request.flags.dnt && !config.embed.dnt) { window._vuid = [ ['pid', config.request.session] ]; var vim = document.createElement('script'); vim.async = true; vim.src = config.request.urls.vuid_js; firstScript.parentNode.insertBefore(vim, firstScript); } }(document, document.getElementById('player'))); </script> </body> </html>"; 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