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

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

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php