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

/
/
gm

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)(\*\*NOTE\*\*: )_([^_]*)_\n" Local $sString = "JavaScript run in the browser has one set of rules when run in a" & @CRLF & _ "browser, and another set when run outside a browser. If you are using" & @CRLF & _ "JavaScript primarily to write client side scripts meant to be run in a" & @CRLF & _ "browser, then it is best to learn JavaScript, and develop JavaScript," & @CRLF & _ "under that scenario. It is true that there are legitimate and important" & @CRLF & _ "ways to run JavaScript from outside the browser. For instance, you can" & @CRLF & _ "run JavaScript from the command prompt, or directly from inside some" & @CRLF & _ "IDEs. At first, however, such stratagems can lead to much confusion. As" & @CRLF & _ "a result, I suggest that you begin by developing JavaScript inside a" & @CRLF & _ "browser." & @CRLF & _ "" & @CRLF & _ "**NOTE**: _I should probably qualify what I say above. The basic syntax" & @CRLF & _ "of the language does not change when you switch from a browser to some" & @CRLF & _ "environment. (The only exception, of course, is when a browser has a" & @CRLF & _ "buggy implementation of JavaScript, and that still happens quite" & @CRLF & _ "frequently.) But even when everything works correctly, certain key" & @CRLF & _ "features of the language, such as the **this** keyword, have a" & @CRLF & _ "different significance inside a browser and outside a browser. Also, key" & @CRLF & _ "elements of the API, such as the **alert** function, are available in a" & @CRLF & _ "browser and not outside a browser. These and other differences become" & @CRLF & _ "manageable when you gain proficiency in the language, but at first, it" & @CRLF & _ "is best to avoid such subtle pitfalls by running JavaScript in the" & @CRLF & _ "environment in which you intend to use it. Of course, if you are" & @CRLF & _ "intending to write mostly server side JavaScript with **nodejs**, then" & @CRLF & _ "this advice is less convincing. I don't not think there are serious" & @CRLF & _ "disadvantages to learning JavaScript in a browser even if you want to" & @CRLF & _ "use it on the server side, but you will find that there are differences." & @CRLF & _ "In general, I think it is easier to move from the browser to **nodejs**," & @CRLF & _ "than it is to move from **nodejs** to the quirky world of browsers._" & @CRLF & _ "" & @CRLF & _ "It turns out that the code you saw in the previous section provides a" & @CRLF & _ "good framework for beginning and intermediate level JavaScript" & @CRLF & _ "programmers who want to learn more about the langauge. Start out by" & @CRLF & _ "opening up code similar to what you see in Listing 3 and 4. As a matter" & @CRLF & _ "of fact, you can simply reuse VerySimple.html over and over again. As we" & @CRLF & _ "explore the JavaScript language, all you need do is change the name of" & @CRLF & _ "the JavaScript file that you are linking in. For instance, linking" & @CRLF & _ "VerySimple01.js for one program, then VerySimple02.js for the next" & @CRLF & _ "program. Better yet, follow best practices and rename each JavaScript" & @CRLF & _ "file to reflect its contents. For instance, ExploringLoops.js would be a" & @CRLF & _ "good name for a JavaScript file that you created when you wanted to" & @CRLF & _ "learn about how loops are written in JavaScript." Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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