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"
"

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 = ".*@(\S+)" Local $sString = "From: <email@example.com> FROM name fails" & @CRLF & _ "" & @CRLF & _ "Closed (fixed)" & @CRLF & _ "Project: " & @CRLF & _ "SMTP Authentication Support" & @CRLF & _ "Version: " & @CRLF & _ "6.x-1.0-beta5" & @CRLF & _ "Component: " & @CRLF & _ "Code" & @CRLF & _ "Priority: " & @CRLF & _ "Normal" & @CRLF & _ "Category: " & @CRLF & _ "Bug report" & @CRLF & _ "Assigned: " & @CRLF & _ "José San Martin" & @CRLF & _ "Reporter: " & @CRLF & _ "goose2000" & @CRLF & _ "Created: " & @CRLF & _ "July 8, 2008 - 12:54" & @CRLF & _ "Updated: " & @CRLF & _ "October 5, 2012 - 19:01" & @CRLF & _ "Log in or register to update this issue" & @CRLF & _ "Jump to:" & @CRLF & _ "Most recent attachment" & @CRLF & _ "Hi, my development site is running on IIS with SMTP server. Mail is working fine when creating new users or getting a password reset. I have built a webform and upon submitting I'll get this error:" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " * warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\Inetpub\wwwroot\BHI_dev\includes\mail.inc on line 193." & @CRLF & _ " * Unable to send e-mail. Please contact the site admin, if the problem persists." & @CRLF & _ "" & @CRLF & _ "The address I use in my testing are in fact completely valid. Seems like webform is not playing nice with the core somehow. Further ideas?" & @CRLF & _ "" & @CRLF & _ "Using Drupal 6.2." & @CRLF & _ "" & @CRLF & _ "Thanks." & @CRLF & _ "" & @CRLF & _ "Files: " & @CRLF & _ "Comment File Size Author" & @CRLF & _ "#25 smtp_279836.patch 694 bytes scttnlsn" & @CRLF & _ "#13 smtp_module_name_patch_279836_01.patch 724 bytes franz" & @CRLF & _ "#6 smtp_module_name_patch_279836_01.patch 724 bytes rfay" & @CRLF & _ "Comments" & @CRLF & _ " goose2000’s picture" & @CRLF & _ "Comment #1goose2000 CreditAttribution: goose2000 commented 8 years ago" & @CRLF & _ "Priority: Critical » Minor" & @CRLF & _ "This seems to be an IIS SMTP issue only. See here:" & @CRLF & _ "" & @CRLF & _ "http://drupal.org/node/33967" & @CRLF & _ "" & @CRLF & _ "Easy work around is to have no 'name' text , just the email address when you configure webform." & @CRLF & _ "Think it may still be fixable at the code? I set it to 'minor' now." & @CRLF & _ "" & @CRLF & _ "Working great, one of the best modules around." & @CRLF & _ "Log in or register to post comments" & @CRLF & _ " quicksketch’s picture" & @CRLF & _ "Comment #2quicksketch CreditAttribution: quicksketch commented 7 years ago" & @CRLF & _ "Title: Email Invalid Address » "Name" <email@example.com> FROM name fails" & @CRLF & _ "Project: Webform » SMTP Authentication Support" & @CRLF & _ "Version: 6.x-2.1.1 » 6.x-1.0-beta3" & @CRLF & _ "Moving to the SMTP module." & @CRLF & _ "" & @CRLF & _ "To summarize, Webform users have not been able to send e-mails when using the SMTP module and the FROM e-mail addresses are formatted as "First Last" <email@example.com>. The name is properly mime_header_encoded when necessary." & @CRLF & _ "" & @CRLF & _ "Any users experiencing this issue, please update with the version of SMTP module you're using." Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH) ; 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