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

r"
"
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)(?<=\d{4}\/\d{2}\/\d{2}\/)\w+\-?\w?\/?\w+\/" Local $sString = "" & @CRLF & _ "http://www.nytimes.com/2015/12/27/nyregion/anxiety-aside-new-york-sees-drop-in-crime.html" & @CRLF & _ "http://www.nytimes.com/2015/12/28/us/politics/state-level-brawls-over-medicaid-reflect-wider-war-in-gop.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/28/us/rahm-emanuel-under-siege-in-chicago-shows-contrite-side.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/28/world/middleeast/syria-refugees-alan-aylan-kurdi.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/28/us/politics/how-hillary-clinton-went-undercover-to-examine-race-in-education.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/28/arts/ellsworth-kelly-artist-who-mixed-european-abstraction-into-everyday-life-dies-at-92.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/28/world/middleeast/more-and-more-special-forces-become-obamas-military-answer.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/us/tamir-rice-police-shootiing-cleveland.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/middleeast/iraq-ramadi-isis.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/business/tsa-moves-closer-to-rejecting-some-state-drivers-licenses-for-travel.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/nyregion/mayor-de-blasio-still-trying-fitfully-to-blow-his-own-horn-better.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/middleeast/iran-hands-over-stockpile-of-enriched-uranium-to-russia.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/asia/comfort-women-south-korea-japan.html" & @CRLF & _ "http://www.nytimes.com/2015/12/29/us/tamir-rice-police-shootiing-cleveland.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/middleeast/iraq-ramadi-isis.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/americas/maritime-repo-men-a-last-resort-for-stolen-ships.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/technology/universities-race-to-nurture-start-up-founders-of-the-future.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/sports/basketball/meadowlark-lemon-harlem-globetrotter-who-played-basketball-and-pranks-with-virtuosity-dies-at-83.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/29/world/asia/comfort-women-south-korea-japan.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/30/business/economy/for-the-wealthiest-private-tax-system-saves-them-billions.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/us/affluenza-ethan-couch-mexico.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/us/use-of-affluenza-didnt-begin-with-ethan-couch-case.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/world/asia/book-says-zhou-enlai-chinese-premier-may-have-been-gay.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/world/middleeast/isis-ramadi-iraq.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/world/europe/us-says-airstrikes-killed-militants-tied-to-paris-attacks.html" & @CRLF & _ "http://www.nytimes.com/2015/12/30/business/economy/for-the-wealthiest-private-tax-system-saves-them-billions.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/30/us/politics/ex-ally-donald-trump-now-heaps-scorn-on-bill-clinton.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/30/us/more-police-officers-facing-charges-but-few-see-jail.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/30/nyregion/bratton-rebukes-kelly-for-questioning-new-york-crime-data-shame-on-him.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/30/us/affluenza-ethan-couch-mexico.html?ref=todayspaper" & @CRLF & _ "http://www.nytimes.com/2015/12/31/business/media/bill-cosby-charged-in-sexual-assault-case.html" & @CRLF & _ "http://www.nytimes.com/2015/07/19/arts/bill-cosby-deposition-reveals-calculated-pursuit-of-young-women-using-fame-drugs-and-deceit.html" & @CRLF & _ "http://www.nytimes.com/2015/12/31/world/europe/cellphone-contacts-in-paris-attacks-suggest-foreign-coordination.html" & @CRLF & _ "http://www.nytimes.com/2015/12/31/world/middleeast/muslims-on-twitter-say-they-have-better-things-to-do-than-join-isis.html" & @CRLF & _ "http://www.nytimes.com/2015/12/31/world/europe/belgium-brussels-police-orgy.html" 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