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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(\/\*(.|\s)*?\*\/|(\n|\t|\r|\v|\f|\a){1,}|\s(?=\s)|(?<=})\s|(?<={)\s|\s(?={)|\s(?=})|(?<=;)\s|[[:blank:]](?=;)|(?<=:)[[:blank:]]|(?<=,)[[:blank:]])" Local $sString = "@import url(//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=latin-ext,latin);" & @CRLF & _ "" & @CRLF & _ "/* Generic */" & @CRLF & _ "body {" & @CRLF & _ "font-family: "Open Sans", sans-serif;" & @CRLF & _ "font-size:13px;" & @CRLF & _ "background:#fcfcfc;" & @CRLF & _ "padding:0;" & @CRLF & _ "margin:8px 8px 0 8px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "textarea {resize:none;outline:none;}" & @CRLF & _ "" & @CRLF & _ "a:link, a:hover {" & @CRLF & _ " color: #2B6FB6;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "a:visited {" & @CRLF & _ " color: #3C2BB6;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ ".nowrap {white-space: nowrap}" & @CRLF & _ "" & @CRLF & _ "/* Forms */" & @CRLF & _ "form {margin: 0;}" & @CRLF & _ "fieldset {margin:0; padding:4px; border:1px solid #dfdfdf; font-family:Verdana, Arial; font-size:10px;}" & @CRLF & _ "legend {color:#2B6FB6; font-weight:bold;}" & @CRLF & _ "label.msg {display:none;}" & @CRLF & _ "label.invalid {color:#EE0000; display:inline;}" & @CRLF & _ "input.invalid {border:1px solid #EE0000;}" & @CRLF & _ "input {background:#FFF; border:1px solid #dfdfdf;}" & @CRLF & _ "input, select, textarea {font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;}" & @CRLF & _ "input, select, textarea {border:1px solid #dfdfdf;}" & @CRLF & _ "input.radio {border:1px none #000000; background:transparent; vertical-align:middle;}" & @CRLF & _ "input.checkbox {border:1px none #000000; background:transparent; vertical-align:middle;}" & @CRLF & _ ".input_noborder {border:0;}" & @CRLF & _ "" & @CRLF & _ "/* Buttons */" & @CRLF & _ "#insert," & @CRLF & _ "#cancel," & @CRLF & _ "#apply," & @CRLF & _ ".mceActionPanel .button," & @CRLF & _ "input.mceButton," & @CRLF & _ ".updateButton {" & @CRLF & _ " display: inline-block;" & @CRLF & _ " text-decoration: none;" & @CRLF & _ " border: 1px solid #adadad;" & @CRLF & _ " margin: 0;" & @CRLF & _ " padding: 0 10px 1px;" & @CRLF & _ " font-size: 13px;" & @CRLF & _ " height: 24px;" & @CRLF & _ " line-height: 22px;" & @CRLF & _ " color: #333;" & @CRLF & _ " cursor: pointer;" & @CRLF & _ " -webkit-border-radius: 3px;" & @CRLF & _ " -webkit-appearance: none;" & @CRLF & _ " border-radius: 3px;" & @CRLF & _ " white-space: nowrap;" & @CRLF & _ " -webkit-box-sizing: border-box;" & @CRLF & _ " -moz-box-sizing: border-box;" & @CRLF & _ " box-sizing: border-box;" & @CRLF & _ " background: #fafafa;" & @CRLF & _ " background-image: -webkit-gradient(linear, left top, left bottom, from(#fafafa), to(#e9e9e9));" & @CRLF & _ " background-image: -webkit-linear-gradient(top, #fafafa, #e9e9e9);" & @CRLF & _ " background-image: -moz-linear-gradient(top, #fafafa, #e9e9e9);" & @CRLF & _ " background-image: -o-linear-gradient(top, #fafafa, #e9e9e9);" & @CRLF & _ " background-image: linear-gradient(to bottom, #fafafa, #e9e9e9);" & @CRLF & _ " " & @CRLF & _ " text-shadow: 0 1px 0 #fff;" & @CRLF & _ " -webkit-box-shadow: inset 0 1px 0 #fff;" & @CRLF & _ " -moz-box-shadow: inset 0 1px 0 #fff;" & @CRLF & _ " box-shadow: inset 0 1px 0 #fff;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#insert {" & @CRLF & _ " background: #2ea2cc;" & @CRLF & _ " background: -webkit-gradient(linear, left top, left bottom, from(#2ea2cc), to(#1e8cbe));" & @CRLF & _ " background: -webkit-linear-gradient(top, #2ea2cc 0%,#1e8cbe 100%);" & @CRLF & _ " background: linear-gradient(top, #2ea2cc 0%,#1e8cbe 100%);" & @CRLF & _ " filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2ea2cc', endColorstr='#1e8cbe',GradientType=0 );" & @CRLF & _ " border-color: #0074a2;" & @CRLF & _ " -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.5);" & @CRLF & _ " box-shadow: inset 0 1px 0 rgba(120,200,230,0.5);" & @CRLF & _ " color: #fff;" & @CRLF & _ " text-decoration: none;" & @CRLF & _ " text-shadow: 0 1px 0 rgba(0,86,132,0.7);" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#cancel:hover," & @CRLF & _ "input.mceButton:hover," & @CRLF & _ ".updateButton:hover," & @CRLF & _ "#cancel:focus," & @CRLF & _ "input.mceButton:focus," & @CRLF & _ ".updateButton:focus {" & @CRLF & _ " background: #f3f3f3;" & @CRLF & _ " background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3));" & @CRLF & _ " background-image: -webkit-linear-gradient(top, #fff, #f3f3f3);" & @CRLF & _ " background-image: -moz-linear-gradient(top, #fff, #f3f3f3);" & @CRLF & _ " background-image: -ms-linear-gradient(top, #fff, #f3f3f3);" & @CRLF & _ " background-image: -o-linear-gradient(top, #fff, #f3f3f3);" & @CRLF & _ " background-image: linear-gradient(to bottom, #fff, #f3f3f3);" & @CRLF & _ " border-color: #999;" & @CRLF & _ " color: #222;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "#insert:hover," & @CRLF & _ "#insert:focus {" & @CRLF & _ " background: #1e8cbe;" & @CRLF & _ " background: -webkit-gradient(linear, left top, left bottom, from(#1e8cbe), to(#0074a2));" & @CRLF & _ " background: -webkit-linear-gradient(top, #1e8cbe 0%,#0074a2 100%);" & @CRLF & _ " background: linear-gradient(top, #1e8cbe 0%,#0074a2 100%);" & @CRLF & _ " filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e8cbe', endColorstr='#0074a2',GradientType=0 );" & @CRLF & _ " border-color: #0074a2;" & @CRLF & _ " -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);" & @CRLF & _ " box-shadow: inset 0 1px 0 rgba(120,200,230,0.6);" & @CRLF & _ " color: #fff;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ ".mceActionPanel #insert {" & @CRLF & _ " float: right;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/* Browse */" & @CRLF & _ "a.pickcolor, a.browse {text-decoration:none}" & @CRLF & _ "a.browse span {display:block; width:20px; height:18px; border:1px solid #FFF; margin-left:1px;}" & @CRLF & _ ".mceOldBoxModel a.browse span {width:22px; height:20px;}" & @CRLF & _ "a.browse:hover span {border:1px solid #0A246A; background-color:#B2BBD0;}" & @CRLF & _ "a.browse span.disabled {border:1px solid white; opacity:0.3; -ms-filter:'alpha(opacity=30)'; filter:alpha(opacity=30);}" & @CRLF & _ "a.browse:hover span.disabled {border:1px solid white; background-color:transparent;}" & @CRLF & _ "a.pickcolor span {display:block; width:20px; height:16px; margin-left:2px;}" & @CRLF & _ ".mceOldBoxModel a.pickcolor span {width:21px; height:17px;}" & @CRLF & _ "a.pickcolor:hover span {background-color:#B2BBD0;}" & @CRLF & _ "div.iframecontainer {background: #fff;}" & @CRLF & _ "" & @CRLF & _ "/* Charmap */" & @CRLF & _ "table.charmap {border:1px solid #AAA; text-align:center}" & @CRLF & _ "td.charmap, #charmap a {width:18px; height:18px; color:#000; border:1px solid #AAA; text-align:center; font-size:12px; vertical-align:middle; line-height: 18px;}" & @CRLF & _ "#charmap a {display:block; color:#000; text-decoration:none; border:0}" & @CRLF & _ "#charmap a:hover {background:#CCC;color:#2B6FB6}" & @CRLF & _ "#charmap #codeN {font-size:10px; font-family:Arial,Helvetica,sans-serif; text-align:center}" & @CRLF & _ "#charmap #codeV {font-size:40px; height:80px; border:1px solid #AAA; text-align:center}" & @CRLF & _ "#charmap #charmapView {background-color:#fff;}" & @CRLF & _ "" & @CRLF & _ "/* Source */" & @CRLF & _ ".wordWrapCode {vertical-align:middle; border:1px none #000000; background:transparent;}" & @CRLF & _ ".mceActionPanel {margin-top:5px;}" & @CRLF & _ "" & @CRLF & _ "/* Tabs classes */" & @CRLF & _ ".tabs {width:100%; height:19px; line-height:normal; border-bottom: 1px solid #aaa;}" & @CRLF & _ ".tabs ul {margin:0; padding:0; list-style:none;}" & @CRLF & _ ".tabs li {float:left; border: 1px solid #aaa; margin:0 2px 0 0; padding:0 0 0 10px; line-height:17px; height:18px; display:block;}" & @CRLF & _ ".tabs li.current {border-bottom: 1px solid #fff; margin-right:2px;}" & @CRLF & _ ".tabs span {float:left; display:block; padding:0px 10px 0 0;}" & @CRLF & _ ".tabs a {text-decoration:none; font-family:Verdana, Arial; font-size:10px;}" & @CRLF & _ ".tabs a:link, .tabs a:visited, .tabs a:hover {color:black;}" & @CRLF & _ "" & @CRLF & _ ".wp-core-ui #tabs {" & @CRLF & _ " padding-bottom: 5px;" & @CRLF & _ " background-color: transparent;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ ".wp-core-ui #tabs a {" & @CRLF & _ " padding: 6px 10px;" & @CRLF & _ " margin: 0 2px;" & @CRLF & _ "}" & @CRLF & _ "" & @CRLF & _ "/* Panels */" & @CRLF & _ ".panel_wrapper div.panel {display:none;}" & @CRLF & _ ".panel_wrapper div.current {display:block; width:100%; height:300px; overflow:visible;}" & @CRLF & _ ".panel_wrapper {border:1px solid #919B9C; border-top:0px; padding:10px; padding-top:5px; clear:both; background:white;}" & @CRLF & _ "" & @CRLF & _ "/* Columns */" & @CRLF & _ ".column {float:left;}" & @CRLF & _ ".properties {width:100%;}" & @CRLF & _ ".properties .column1 {}" & @CRLF & _ ".properties .column2 {text-align:left;}" & @CRLF & _ "" & @CRLF & _ "/* Titles */" & @CRLF & _ "h1, h2, h3, h4 {color:#2B6FB6; margin:0; padding:0; padding-top:5px;}" & @CRLF & _ "h3 {font-size:14px;}" & @CRLF & _ ".title {font-size:12px; font-weight:bold; color:#2B6FB6;}" & @CRLF & _ "" & @CRLF & _ "/* Dialog specific */" & @CRLF & _ "#link .panel_wrapper, #link div.current {height:125px;}" & @CRLF & _ "#image .panel_wrapper, #image div.current {height:200px;}" & @CRLF & _ "#plugintable thead {font-weight:bold; background:#DDD;}" & @CRLF & _ "#plugintable, #about #plugintable td {border:1px solid #919B9C;}" & @CRLF & _ "#plugintable {width:96%; margin-top:10px;}" & @CRLF & _ "#pluginscontainer {height:290px; overflow:auto;}" & @CRLF & _ "#colorpicker #preview {display:inline-block; padding-left:40px; height:14px; border:1px solid black; margin-left:5px; margin-right: 5px}" & @CRLF & _ "#colorpicker #previewblock {position: relative; top: -3px; padding-left:5px; padding-top: 0px; display:inline}" & @CRLF & _ "#colorpicker #preview_wrapper {text-align:center; padding-top:4px; white-space: nowrap; float: right;}" & @CRLF & _ "#colorpicker #insert, #colorpicker #cancel {width: 90px}" & @CRLF & _ "#colorpicker #colors {float:left; border:1px solid gray; cursor:crosshair;}" & @CRLF & _ "#colorpicker #light {border:1px solid gray; margin-left:5px; float:left;width:15px; height:150px; cursor:crosshair;}" & @CRLF & _ "#colorpicker #light div {overflow:hidden;}" & @CRLF & _ "#colorpicker .panel_wrapper div.current {height:175px;}" & @CRLF & _ "#colorpicker #namedcolors {width:150px;}" & @CRLF & _ "#colorpicker #namedcolors a {display:block; float:left; width:10px; height:10px; margin:1px 1px 0 0; overflow:hidden;}" & @CRLF & _ "#colorpicker #colornamecontainer {margin-top:5px;}" & @CRLF & _ "#colorpicker #picker_panel fieldset {margin:auto;width:325px;}" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "/* Localization */ " & @CRLF & _ "" & @CRLF & _ "body[dir="rtl"]," & @CRLF & _ "body[dir="rtl"] fieldset," & @CRLF & _ "body[dir="rtl"] input, body[dir="rtl"] select, body[dir="rtl"] textarea," & @CRLF & _ "body[dir="rtl"] #charmap #codeN," & @CRLF & _ "body[dir="rtl"] .tabs a {" & @CRLF & _ " font-family: Tahoma, sans-serif;" & @CRLF & _ "}" & @CRLF & _ "" Local $sSubst = "" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm