Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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 = @"^\s*# each header may be up to 12392 bytes\. This is the SPNEGO authentication header size limit."; string input = @"<VirtualHost 0.0.0.0:${JIVE_HTTPD_PORT}> DocumentRoot ""${JIVE_HOME}/var/www"" ErrorDocument 404 /___sbsstatic___/404.html ErrorDocument 500 /___sbsstatic___/500.html ErrorDocument 501 /___sbsstatic___/catchall.html ErrorDocument 502 /___sbsstatic___/catchall.html ErrorDocument 503 /___sbsstatic___/maintenance.html ErrorDocument 504 /___sbsstatic___/maintenance.html ErrorDocument 505 /___sbsstatic___/catchall.html <Directory /> Options FollowSymLinks Require all denied </Directory> <Directory ${JIVE_HOME}/applications/*/home/www> Options FollowSymLinks Require all granted </Directory> <Directory ${JIVE_HOME}/var/www/resources> Options -Indexes </Directory> LogLevel info CustomLog ""${LOG_DIR}/jive-httpd-access.log"" common ErrorLog ""${LOG_DIR}/jive-httpd-error.log"" RequestHeader set X-Forwarded-Secure ""false"" ProxyRequests Off ProxyPreserveHost on Header edit Set-Cookie ""(?<!;\sHttpOnly)$"" "";HttpOnly"" # The JCAPI-Token (CSRF protection via double-submit cookie) needs to accessible, so strip HttpOnly Header edit Set-Cookie (JCAPI-Token=.*);\s?HttpOnly$ $1 # each header may be up to 12392 bytes. This is the SPNEGO authentication header size limit. LimitRequestFieldsize 12392 RewriteEngine On RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/images/(.*)$ /images/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/scripts/(.*)$ /scripts/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/styles/(.*)$ /styles/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/resources/(.*)$ /resources/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/__services/(.*)$ /__services/$1 [PT] # Serve gzip compressed JS files if they exist and the client accepts gzip. RewriteCond %{HTTP:Accept-encoding} gzip RewriteCond %{REQUEST_FILENAME}\.gz -s RewriteRule ^(.*)\.js $1\.js\.gz [QSA] # Serve correct content types, and prevent mod_deflate double gzip. RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1] # Replace double dashes on project urls to keep old links working on updated instances RewriteRule ^(.*/projects/.*)--(.*)$ $1-$2 [L,R=301] CacheMaxFileSize 5242880 CacheEnable mem /images/ CacheEnable mem /scripts/ CacheEnable mem /styles/ CacheEnable mem /resources/ CacheIgnoreHeaders Set-Cookie X-JIVE-USER-ID # Header unset X-JIVE-USER-ID ExpiresActive On ExpiresDefault ""now"" ExpiresByType image/gif ""access plus 10 years"" ExpiresByType image/png ""access plus 10 years"" ExpiresByType image/jpeg ""access plus 10 years"" ExpiresByType image/x-icon ""access plus 10 years"" ExpiresByType text/css ""access plus 10 years"" ExpiresByType application/javascript ""access plus 10 years"" ExpiresByType application/x-shockwave-flash ""access plus 10 years"" <LocationMatch ""\.(woff|eot|ttf|svg)$""> ExpiresDefault ""access plus 10 years"" </LocationMatch> ProxyPass /___sbsstatic___/ ! ProxyPass /images/ ! ProxyPass /styles/ ! ProxyPass /scripts/ ! ProxyPass /resources/scripts/ ! ProxyPass /resources/images/ ! ProxyPass /resources/styles/ ! ProxyPass /resources/statics/ ! Include sites/proxies/*.conf Include sites/conf.d/*.conf </VirtualHost> <IfDefine SSL> Listen ${SSL_PORT} <VirtualHost 0.0.0.0:${SSL_PORT}> DocumentRoot ""${JIVE_HOME}/var/www"" ErrorDocument 404 /___sbsstatic___/404.html ErrorDocument 500 /___sbsstatic___/500.html ErrorDocument 501 /___sbsstatic___/catchall.html ErrorDocument 502 /___sbsstatic___/catchall.html ErrorDocument 503 /___sbsstatic___/maintenance.html ErrorDocument 504 /___sbsstatic___/maintenance.html ErrorDocument 505 /___sbsstatic___/catchall.html <Directory /> Options FollowSymLinks Require all granted SSLRequireSSL </Directory> <Directory ${JIVE_HOME}/var/www/resources> Options -Indexes </Directory> LogLevel info CustomLog ""${LOG_DIR}/jive-httpd-ssl-access.log"" common ErrorLog ""${LOG_DIR}/jive-httpd-ssl-error.log"" RequestHeader set X-Forwarded-Secure ""true"" ProxyRequests Off ProxyPreserveHost On RewriteEngine On RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/images/(.*)$ /images/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/scripts/(.*)$ /scripts/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/styles/(.*)$ /styles/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/resources/(.*)$ /resources/$1 RewriteRule ^/[0-9]\.[0-9]\.[0-9]{1,3}\.[0-9a-f]{1,10}/__services/(.*)$ /__services/$1 [PT] # Serve gzip compressed JS files if they exist and the client accepts gzip. RewriteCond %{HTTP:Accept-encoding} gzip RewriteCond %{REQUEST_FILENAME}\.gz -s RewriteRule ^(.*)\.js $1\.js\.gz [QSA] # Serve correct content types, and prevent mod_deflate double gzip. RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1] # Replace double dashes on project urls to keep old links working on updated instances RewriteRule ^(.*/projects/.*)--(.*)$ $1-$2 [L,R=301] CacheMaxFileSize 5242880 CacheEnable mem /styles/ CacheEnable mem /images/ CacheEnable mem /scripts/ CacheEnable mem /resources/ CacheIgnoreHeaders Set-Cookie X-JIVE-USER-ID # Header unset X-JIVE-USER-ID ExpiresActive On ExpiresDefault ""now"" ExpiresByType image/gif ""access plus 10 years"" ExpiresByType image/png ""access plus 10 years"" ExpiresByType image/jpeg ""access plus 10 years"" ExpiresByType image/x-icon ""access plus 10 years"" ExpiresByType text/css ""access plus 10 years"" ExpiresByType application/javascript ""access plus 10 years"" ExpiresByType application/x-shockwave-flash ""access plus 10 years"" <LocationMatch ""\.(woff|eot|ttf|svg)$""> ExpiresDefault ""access plus 10 years"" </LocationMatch> ProxyPass /___sbsstatic___/ ! ProxyPass /images/ ! ProxyPass /styles/ ! ProxyPass /scripts/ ! ProxyPass /resources/scripts/ ! ProxyPass /resources/images/ ! ProxyPass /resources/styles/ ! ProxyPass /resources/statics/ ! Include sites/proxies/*.conf Include sites/conf.d/*.conf SSLEngine on SSLCipherSuite ALL:!ADH:!LOW:!EXP:!SSLv2:!NULL:RC4:RSA:HIGH:MEDIUM SSLCertificateFile ""${SSL_CERTIFICATE_FILE}"" SSLCertificateKeyFile ""${SSL_CERTIFICATE_KEY_FILE}"" </VirtualHost> </IfDefine>"; 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