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

/
/
gi

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 = "(?i)(on|date)*\s*\,*(mon|tue|wed|thu|fri|sat)\,*\s*([0-9]{2,4}|([0-9]{2}:*){1,3})\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+([0-9]{2,4}|([0-9]{2}:*){1,3})\s+(([0-9]{2}:*){1,3}|[0-9]{2,4})\s*((\+|\-)+(([0-9]{2}:*){1,3}|[0-9]{2,4}))*" & @CRLF & _ "" Local $sString = "From ilug-admin@linux.ie Wed Aug 21 13:33:23 2002" & @CRLF & _ "Return-Path: <ilug-admin@linux.ie>" & @CRLF & _ "Delivered-To: yyyy@localhost.netnoteinc.com" & @CRLF & _ "Received: from localhost (localhost [127.0.0.1])" & @CRLF & _ " by phobos.labs.netnoteinc.com (Postfix) with ESMTP id E0EBC43C34" & @CRLF & _ " for <jm@localhost>; Wed, 21 Aug 2002 08:33:21 -0400 (EDT)" & @CRLF & _ "Received: from phobos [127.0.0.1]" & @CRLF & _ " by localhost with IMAP (fetchmail-5.9.0)" & @CRLF & _ " for jm@localhost (single-drop); Wed, 21 Aug 2002 13:33:21 +0100 (IST)" & @CRLF & _ "Received: from lugh.tuatha.org (root@lugh.tuatha.org [194.125.145.45]) by" & @CRLF & _ " dogma.slashnull.org (8.11.6/8.11.6) with ESMTP id g7LCYUZ24675 for" & @CRLF & _ " <jm-ilug@jmason.org>; Wed, 21 Aug 2002 13:34:30 +0100" & @CRLF & _ "Received: from lugh (root@localhost [127.0.0.1]) by lugh.tuatha.org" & @CRLF & _ " (8.9.3/8.9.3) with ESMTP id NAA29496; Wed, 21 Aug 2002 13:33:16 +0100" & @CRLF & _ "X-Authentication-Warning: lugh.tuatha.org: Host root@localhost [127.0.0.1]" & @CRLF & _ " claimed to be lugh" & @CRLF & _ "Received: from salmon.maths.tcd.ie (mmdf@salmon.maths.tcd.ie" & @CRLF & _ " [134.226.81.11]) by lugh.tuatha.org (8.9.3/8.9.3) with SMTP id NAA29463" & @CRLF & _ " for <ilug@linux.ie>; Wed, 21 Aug 2002 13:33:07 +0100" & @CRLF & _ "Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id" & @CRLF & _ " <aa96976@salmon>; 21 Aug 2002 13:33:06 +0100 (BST)" & @CRLF & _ "To: ilug@linux.ie" & @CRLF & _ "Subject: Re: [ILUG] URGENT: Cant get a skrew out... PLEASE HELP!" & @CRLF & _ "X-It'S: all good" & @CRLF & _ "X-Wigglefluff: fuddtastic" & @CRLF & _ "X-Zippy: When this load is DONE I think I'll wash it AGAIN.." & @CRLF & _ "In-Reply-To: Your message of" & @CRLF & _ " "Wed, 21 Aug 2002 12:42:17 BST."" & @CRLF & _ " <BCEFLMCEIJHPCPLGADJICEDPCAAA.kialllists@redpie.com>" & @CRLF & _ "Date: Wed, 21 Aug 2002 13:33:06 +0100" & @CRLF & _ "From: Niall Brady <bradyn@maths.tcd.ie>" & @CRLF & _ "Message-Id: <200208211333.aa96976@salmon.maths.tcd.ie>" & @CRLF & _ "Sender: ilug-admin@linux.ie" & @CRLF & _ "Errors-To: ilug-admin@linux.ie" & @CRLF & _ "X-Mailman-Version: 1.1" & @CRLF & _ "Precedence: bulk" & @CRLF & _ "List-Id: Irish Linux Users' Group <ilug.linux.ie>" & @CRLF & _ "X-Beenthere: ilug@linux.ie" & @CRLF & _ "" & @CRLF & _ "On Wed, 21 Aug 2002 12:42:17 BST, Kiall Mac Innes said:" & @CRLF & _ ">Hi i have a phillips head skrew thats holding a circut board together i need" & @CRLF & _ ">to take it out ASAP and nothing will work, the threads on the skrew are" & @CRLF & _ ">almost completly gone, its is a very small skrew that i have to use a" & @CRLF & _ ">percision skrewdriver set to remove the skrews any help would be" & @CRLF & _ ">appreaciated..." & @CRLF & _ "" & @CRLF & _ "Get a very, *very* small set of drill bits. Start drilling right" & @CRLF & _ "through the center of the head, at a slow speed so you don't pop" & @CRLF & _ "off and through the board! Once you have a bit of an indent in," & @CRLF & _ "increase the speed a little bit." & @CRLF & _ "" & @CRLF & _ "If you've made a deepish indent, and the head doesn't pop off, use" & @CRLF & _ "the next largest drill bit you have. Repeat until happy." & @CRLF & _ "" & @CRLF & _ "Eventually the head should just pop off, allowing you to lift the" & @CRLF & _ "board off over the shaft of the screw... then ye can take out the" & @CRLF & _ "rest fairly easily with a pliers or whatnot." & @CRLF & _ "" & @CRLF & _ "-- " & @CRLF & _ " Niall" & @CRLF & _ "" & @CRLF & _ "-- " & @CRLF & _ "Irish Linux Users' Group: ilug@linux.ie" & @CRLF & _ "http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information." & @CRLF & _ "List maintainer: listmaster@linux.ie" & @CRLF & _ "" & @CRLF & _ "" 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