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

/
/
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)\b(Sydney|Melbourne|Brisbane|Adelaide)\b\s[\W\s\r]{0,10}[0-9]{4}\,\s(?<TimeIB>[0-9:APM]{6,7})[\W\s\r]{1,5}[\W\s\rA-Za-z0-9]{5,180}Payment|\b(Sydney|Melbourne|Brisbane|Adelaide)\b\sSUBSIDIARY\/FRANCHISE[\W\s\r]{0,10}[0-9]{4}\,\s(?<TimeIB2>[0-9:APM]{6,7})[\W\s\r]{1,5}[\W\s\rA-Za-z0-9]{5,180}Payment" Local $sString = "E-Ticket Itinerary, Receipt and Tax Invoice" & @CRLF & _ "" & @CRLF & _ "Your Booking Reference" & @CRLF & _ "" & @CRLF & _ "OML4CW" & @CRLF & _ "Important Information" & @CRLF & _ "• This is your E-Ticket Itinerary & Receipt/Tax Invoice. We recommend that you print this out or save this on your phone, and it" & @CRLF & _ "is recommended you retain a copy for your records." & @CRLF & _ "• Each passenger travelling needs a printed copy of this document for airport security checks." & @CRLF & _ "• Please familiarise yourself with the key Conditions of Carriage, Dangerous Goods guide and other information attached." & @CRLF & _ "Passenger Ticket Information" & @CRLF & _ "Passenger Name" & @CRLF & _ "" & @CRLF & _ "Frequent Flyer No." & @CRLF & _ "" & @CRLF & _ "Ticket No." & @CRLF & _ "" & @CRLF & _ "Issued" & @CRLF & _ "" & @CRLF & _ "Mr Matthew Davis" & @CRLF & _ "" & @CRLF & _ "QF1911660387" & @CRLF & _ "Frequent Flyer Silver / oneworld Ruby" & @CRLF & _ "" & @CRLF & _ "081-2498583545" & @CRLF & _ "" & @CRLF & _ "30 Aug 19" & @CRLF & _ "" & @CRLF & _ "Ticket Total*" & @CRLF & _ "423.32" & @CRLF & _ "" & @CRLF & _ "Mr Zachary Kirkham" & @CRLF & _ "" & @CRLF & _ "QF1752890" & @CRLF & _ "Qantas Club Silver / oneworld Ruby" & @CRLF & _ "" & @CRLF & _ "081-2498583544" & @CRLF & _ "" & @CRLF & _ "30 Aug 19" & @CRLF & _ "" & @CRLF & _ "423.32" & @CRLF & _ "" & @CRLF & _ "Ticket Total for all passengers*" & @CRLF & _ "" & @CRLF & _ "846.64" & @CRLF & _ "" & @CRLF & _ "*Amounts are displayed in AUD (AUD)" & @CRLF & _ "" & @CRLF & _ "Your Itinerary" & @CRLF & _ "Date" & @CRLF & _ "" & @CRLF & _ "Flight Number" & @CRLF & _ "" & @CRLF & _ "Departing" & @CRLF & _ "" & @CRLF & _ "Arriving" & @CRLF & _ "" & @CRLF & _ "Status" & @CRLF & _ "" & @CRLF & _ "Flight Information" & @CRLF & _ "" & @CRLF & _ "08 Sep 19" & @CRLF & _ "" & @CRLF & _ "QF435" & @CRLF & _ "" & @CRLF & _ "Sydney" & @CRLF & _ "1300, 1:00PM" & @CRLF & _ "Terminal 3" & @CRLF & _ "" & @CRLF & _ "Melbourne" & @CRLF & _ "1435, 2:35PM" & @CRLF & _ "08 Sep 19" & @CRLF & _ "Terminal 1" & @CRLF & _ "" & @CRLF & _ "Economy" & @CRLF & _ "Confirmed" & @CRLF & _ "" & @CRLF & _ "Est journey Time: 01:35" & @CRLF & _ "Non-Stop" & @CRLF & _ "Aircraft Type: Boeing 737" & @CRLF & _ "" & @CRLF & _ "08 Sep 19" & @CRLF & _ "" & @CRLF & _ "QF2285 Operated By" & @CRLF & _ "Melbourne" & @CRLF & _ "SUBSIDIARY/FRANCHISE 1520, 3:20PM" & @CRLF & _ "Terminal 1" & @CRLF & _ "" & @CRLF & _ "Launceston" & @CRLF & _ "1635, 4:35PM" & @CRLF & _ "08 Sep 19" & @CRLF & _ "" & @CRLF & _ "Economy" & @CRLF & _ "Confirmed" & @CRLF & _ "" & @CRLF & _ "Est journey Time: 01:15" & @CRLF & _ "Non-Stop" & @CRLF & _ "Aircraft Type: De Havilland Dhc-8 Dash" & @CRLF & _ "8-400 Dash 8q" & @CRLF & _ "" & @CRLF & _ "Payment Details" & @CRLF & _ "Date" & @CRLF & _ "" & @CRLF & _ "Payment Type" & @CRLF & _ "" & @CRLF & _ "Reference" & @CRLF & _ "" & @CRLF & _ "30 Aug 19" & @CRLF & _ "" & @CRLF & _ "American Express" & @CRLF & _ "" & @CRLF & _ "xxxx-xxxx-xxxx-2006" & @CRLF & _ "" & @CRLF & _ "Amount*" & @CRLF & _ "846.64" & @CRLF & _ "" & @CRLF & _ "This may appear as multiple transactions on your credit card statement" & @CRLF & _ "" & @CRLF & _ "Your Receipt Details" & @CRLF & _ "Ticket Charges" & @CRLF & _ "Total*" & @CRLF & _ "Card Payment Fee" & @CRLF & _ "" & @CRLF & _ "Total Amount Payable*" & @CRLF & _ "" & @CRLF & _ "Charges" & @CRLF & _ "761.68" & @CRLF & _ "8.00" & @CRLF & _ "" & @CRLF & _ "GST" & @CRLF & _ "" & @CRLF & _ "Total*" & @CRLF & _ "" & @CRLF & _ "769.68" & @CRLF & _ "" & @CRLF & _ "76.96" & @CRLF & _ "" & @CRLF & _ "846.64" & @CRLF & _ "" & @CRLF & _ "*Includes Taxes/Fees/carrier Charges" & @CRLF & _ "" & @CRLF & _ "Tax Information" & @CRLF & _ "GST is included for taxable sales" & @CRLF & _ "ABN:58084409316" & @CRLF & _ "" & @CRLF & _ "Issued by" & @CRLF & _ "Qantas Airways on 30 Aug 19" & @CRLF & _ "" & @CRLF & _ "GST Paid 76.96" & @CRLF & _ "" & @CRLF & _ "Flying With Us" & @CRLF & _ "Before Check-in" & @CRLF & _ "• Ensure that each passenger" & @CRLF & _ "carries a printed copy of this" & @CRLF & _ "document when travelling." & @CRLF & _ "• Label your bags inside and out" & @CRLF & _ "with your name, address and" & @CRLF & _ "contact number at your" & @CRLF & _ "destination." & @CRLF & _ "• Check Carry-on baggage and" & @CRLF & _ "checked baggage allowances as" & @CRLF & _ "restrictions apply." & @CRLF & _ "" & @CRLF & _ "Getting Away On Time" & @CRLF & _ "• Ensure you are at the airport with" & @CRLF & _ "enough time to complete necessary" & @CRLF & _ "check-in, security screening and," & @CRLF & _ "for international flights, customs" & @CRLF & _ "and immigration." & @CRLF & _ "• Familiarise yourself with the checkin and boarding times. Information" & @CRLF & _ "for Qantas and QantasLink flights is" & @CRLF & _ "in the Travel Information section" & @CRLF & _ "attached." & @CRLF & _ "" & @CRLF & _ "Check-in" & @CRLF & _ "• Visit qantas.com/checkin to" & @CRLF & _ "choose the check-in option best" & @CRLF & _ "for you." & @CRLF & _ "" & @CRLF & _ "Fare Restrictions - Refer to the applicable fare rules as special conditions may apply" & @CRLF & _ "Additional Fees: Fees may apply to some booking changes, ticket reissues and consultant-assisted services. Details are available at qantas.com." & @CRLF & _ "" & @CRLF & _ "Qantas Airways Limited ABN 16 009 661 901, 10 Bourke Road, Mascot NSW 2020, Australia" & @CRLF & _ "qantas.com" & @CRLF & _ "" & @CRLF & _ " Travel Information" & @CRLF & _ "Qantas Group check-in times" & @CRLF & _ "" & @CRLF & _ "International Terminal" & @CRLF & _ "" & @CRLF & _ "Domestic Terminal" & @CRLF & _ "" & @CRLF & _ "Australian and New Zealand Terminals**" & @CRLF & _ "" & @CRLF & _ "QF 001 - 399" & @CRLF & _ "" & @CRLF & _ "QF400 and above" & @CRLF & _ "" & @CRLF & _ "International First / Business" & @CRLF & _ "International Economy / Premium Economy" & @CRLF & _ "" & @CRLF & _ "Closes 60 minutes before departure" & @CRLF & _ "Closes 90 minutes before departure" & @CRLF & _ "" & @CRLF & _ "Domestic Business / Economy" & @CRLF & _ "" & @CRLF & _ "Closes 60 minutes before departure" & @CRLF & _ "" & @CRLF & _ "Qantas codeshare services (QF Flight" & @CRLF & _ "numbers operated by Jetstar)^" & @CRLF & _ "Jetstar Services^" & @CRLF & _ "" & @CRLF & _ "Check in opens 3 hours before departure" & @CRLF & _ "Closes 60 minutes before departure" & @CRLF & _ "JQ 001 - 399 and 3K 500 - 699^" & @CRLF & _ "" & @CRLF & _ "N/A" & @CRLF & _ "N/A" & @CRLF & _ "45 minutes from departure* Closes 30" & @CRLF & _ "minutes before departure." & @CRLF & _ "Check in opens 2 hours before departure" & @CRLF & _ "Closes 30 minutes before departure" & @CRLF & _ "JQ 400 and above" & @CRLF & _ "" & @CRLF & _ "Jetstar Business / Economy (JQ)^" & @CRLF & _ "" & @CRLF & _ "Check in opens 3 hours before departure" & @CRLF & _ "Closes 60 minutes before departure" & @CRLF & _ "Check in opens 2 hours before departure" & @CRLF & _ "" & @CRLF & _ "Check in opens 2 hours before departure" & @CRLF & _ "Closes 30 minutes before departure" & @CRLF & _ "N/A" & @CRLF & _ "" & @CRLF & _ "Jetstar flights operated by Jetstar Asia (3K)~" & @CRLF & _ "" & @CRLF & _ "* Check-in closes 30 minutes before departure. Boarding will commence 20 minutes prior to departure. ** Please check with your local Qantas office for check-in" & @CRLF & _ "time at all non-Australian / New Zealand ports. Ensure you adhere to check-in times or your fare may be forfeited." & @CRLF & _ "^ Jetstar flights JQ1-JQ399 depart from international terminals, except JQ61, JQ73 and JQ81 which depart from domestic terminals." & @CRLF & _ "~ Jetstar flights that operate under a 3K flight number between Perth and Singapore and Singapore and Auckland check-in opens 3 hours prior to departure and" & @CRLF & _ "closes 1 hour prior to departure." & @CRLF & _ "" & @CRLF & _ "Included and Carry On Baggage" & @CRLF & _ "" & @CRLF & _ "QF435" & @CRLF & _ "" & @CRLF & _ "Sydney to Melbourne - 08 Sep 2019" & @CRLF & _ "PASSENGER" & @CRLF & _ "" & @CRLF & _ "Mr Matthew Davis" & @CRLF & _ "" & @CRLF & _ "INCLUDED CHECKED BAGGAGE" & @CRLF & _ "(no single piece may exceed 32kg / 67lb)" & @CRLF & _ "" & @CRLF & _ "PURCHASED BAGGAGE" & @CRLF & _ "(no single piece may exceed 32kg / 67lb)" & @CRLF & _ "" & @CRLF & _ "CARRY ON BAGGAGE" & @CRLF & _ "(Up to 10kg(22lb) for one piece, max 14kg(30lb) total)" & @CRLF & _ "" & @CRLF & _ "1 x 32kg/70lb" & @CRLF & _ "" & @CRLF & _ "-" & @CRLF & _ "" & @CRLF & _ "Cabin bag combination + 1 personal item" & @CRLF & _ "" & @CRLF & _ "1 x 32kg/70lb" & @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