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

/
/
m

Test String

Code Generator

Generated Code

const regex = /passengers\*\s+?(?<TotalPrice>[0-9\,\.]{5,8})|Total\*\s+?([0-9\,\.]{5,8})/m; // Alternative syntax using RegExp constructor // const regex = new RegExp('passengers\\*\\s+?(?<TotalPrice>[0-9\\,\\.]{5,8})|Total\\*\\s+?([0-9\\,\\.]{5,8})', 'm') const str = `E-Ticket Itinerary, Receipt and Tax Invoice Your Booking Reference KTHQEJ 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 Zachary Kirkham QF1752890 Qantas Club Silver / oneworld Ruby 081-2301896427 04 Dec 19 Ticket Total* 814.07 Mr Matthew Davis QF1911660387 Frequent Flyer Silver / oneworld Ruby 081-2301896426 04 Dec 19 814.07 Ticket Total for all passengers* 1,628.14 *Amounts are displayed in AUD (AUD) Your Itinerary Date Flight Number Departing Arriving Status Flight Information 09 Dec 19 QF471 Sydney 0615, 6:15AM Terminal 3 Melbourne 0750, 7:50AM 09 Dec 19 Terminal 1 Economy Confirmed Est journey Time: 01:35 Non-Stop Aircraft Type: Boeing 737 11 Dec 19 QF434 Melbourne 1300, 1:00PM Terminal 1 Sydney 1425, 2:25PM 11 Dec 19 Terminal 3 Economy Confirmed Est journey Time: 01:25 Non-Stop Aircraft Type: Boeing 737 Payment Details Date Payment Type Reference 04 Dec 19 American Express xxxx-xxxx-xxxx-2006 Amount* 1,628.14 This may appear as multiple transactions on your credit card statement Your Receipt Details Ticket Charges Total* Card Payment Fee Total Amount Payable* Charges 1,465.04 15.10 GST Total* 1,480.14 148.00 1,628.14 *Includes Taxes/Fees/carrier Charges Tax Information GST is included for taxable sales ABN:58084409316 Issued by Qantas Airways on 04 Dec 19 GST Paid 148.00 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 QF471 Sydney to Melbourne - 09 Dec 2019 PASSENGER Mr Zachary Kirkham 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 1 x 32kg/70lb Cabin bag combination + 1 personal item 1 x 32kg/70lb - Cabin bag combination + 1 personal item Silver QC - 1752890 Adult Mr Matthew Davis Silver - 1911660387 Adult Domestic Economy Checked + Carry On baggage information CHECKED BAGGAGE CARRY ON + L + H + D = 140cm/54in No single item of checked baggage may exceed 32kg (70lb). Dimensions for checked baggage are calculated by adding together the width, height and depth of the piece of baggage. For tickets containing a flight to or from the Americas, the amount is the total of all the baggage added together. Carry-on baggage varies depending on destination, class of travel or aircraft. One small personal item could be a handbag, laptop computer or overcoat. Restrictions on height, depth, length and weight apply to carry-on baggage. More information is on the Carry-on Baggage page. Qantas Airways Limited ABN 16 009 661 901, 10 Bourke Road, Mascot NSW 2020, Australia qantas.com QF434 Melbourne to Sydney - 11 Dec 2019 PASSENGER Mr Zachary Kirkham 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 1 x 32kg/70lb Cabin bag combination + 1 personal item 1 x 32kg/70lb - Cabin bag combination + 1 personal item Silver QC - 1752890 Adult Mr Matthew Davis Silver - 1911660387 Adult Domestic Economy Checked + Carry On baggage information CHECKED BAGGAGE CARRY ON + L + H + D = 140cm/54in No single item of checked baggage may exceed 32kg (70lb). Dimensions for checked baggage are calculated by adding together the width, height and depth of the piece of baggage. For tickets containing a flight to or from the Americas, the amount is the total of all the baggage added together. Carry-on baggage varies depending on destination, class of travel or aircraft. One small personal item could be a handbag, laptop computer or overcoat. Restrictions on height, depth, length and weight apply to carry-on baggage. More information is on the Carry-on Baggage page. Qantas Airways Limited ABN 16 009 661 901, 10 Bourke Road, Mascot NSW 2020, Australia qantas.com Travel Information Important Information Dimensions: International Flights (excluding North and South America): Total dimensions for each piece must not exceed 158cm (62in). Dimensions for checked baggage are calculated by adding together the width, height and depth of the piece of baggage. International Flights to and from North & South America: Total dimensions of the 3 pieces must not exceed 405cm (159in) and total dimensions of the 2 pieces must not exceed 270cm (106in) with no single piece exceeding 158cm (62in). Dimensions for checked baggage are calculated by adding together the width, height and depth of the piece of baggage. Domestic Flights: Total dimensions of each piece must not exceed 140cm (55in). Dimensions for checked baggage are calculated by adding together the width, height and depth of the piece of baggage. +Adults travelling with an infant (under 2 years) on Qantas operated services may check-in up to three infant items free of charge. See here for more details. Interline travel: Qantas baggage allowance may not apply. If your travel on this ticket involves more than one airline, the baggage allowance of the most significant carrier in your itinerary will apply to each journey, except in relation to travel to, from or within the USA. Under US DOT regulations, if your travel to, from or within the USA involves more than one airline, the baggage rules of one airline will apply to all of the flights in your itinerary. This is determined by the first carrier in your itinerary. For travel between Australia and the USA, usually (both not always) Qantas' baggage allowance will apply to the whole itinerary. Member Allowances: Qantas Frequent Flyer and Qantas Club member baggage allowances apply to travel on Qantas and QantasLink operated flights with a QF flight number on your ticket, excluding flights to or from Lord Howe Island and Mount Hotham. These allowances also apply to Emirates operated flights with an EK flight number between and within Europe, the Middle East, North Africa, Asia and Australia. These benefits are not cumulative. Definitions: Domestic travel is travel that is not combined with any international flights on the same ticket. International travel is travel between two or more countries including any flight within those countries if it is combined with the international travel. General: No single item of checked baggage may exceed 32kg (70lb). Carriage of baggage is subject to space availability and any applicable aircraft weight restrictions, which vary. Baggage exceeding the specified allowance may need to be accommodated on a later flight. Visit qantas.com/baggage or the "Planning & Booking - Baggage" page of jetstar.com for important information regarding baggage restrictions. For additional and excess baggage rates visit qantas.com/additionalbaggage or jetstar.com. Qantas Airways Limited ABN 16 009 661 901, 10 Bourke Road, Mascot NSW 2020, Australia qantas.com Travel Information Enhanced Security Screening - Powders, Liquids, aerosols and gels Enhanced security measures apply to and from Australia and on domestic sectors of international flights within Australia. Similar or more restrictive measures may apply for other countries. If you want to take powders, liquids, aerosols or gels through the screening point, make sure: • each item is 100ml or less; • all items fit comfortably in a transparent resealable 1 litre plastic bag (only 1 bag per person is allowed) Travelling with Money Are you planning to carry funds in or out of Australia? By law, you must now: • If asked by a Customs or police officer, report travellers cheques, cheques, money orders or any other bearer negotiable instruments of any amount. • Always report A\$10,000 cash or more (or foreign currency equivalent) using a form available from Customs. Visit www.austrac.gov.au for more information. Exceptions:Prescription and non-prescription medicines and baby products that you need for the flight, but please note: • proof of need may be required, and • additional security checks may be performed • All powders must be screened separately with restrictions on the carriage of inorganic powders over 350 millilitres (350 grams) Qantas Privacy Collection Notice Qantas collects information about you (including health information where necessary) to provide products and services to you, facilitate your participation in our and other organisations' loyalty programs, ensure the safety and security of all passengers when travelling with us, conduct marketing activities for our and third parties' products and services and conduct market research. Note - Duty Free items: Duty free liquids, aerosols and gels not exceeding 100ml per item may be taken onboard in your transparent resealable 1 litre plastic bag. Government screening requirements vary between countries around the world, and duty free liquids, aerosols and gels which exceed 100ml may not always be permitted through a screening point at all airports on your journey. If your journey includes a flight with a transit stop or a transfer to an onward connecting flight, you may be required to take these items through the transit or transfer screening points where you may be required to surrender the item, and it will not be returned to you. We may collect your personal information from people who make or update your travel booking or otherwise interact with us on your behalf, from our related bodies corporate and Jetstar branded entities, from our service providers and from immigration, customs, border security and other regulatory authorities. Some of the information we collect is required under the Customs Act 1901 (Cth). If the information is not provided, we may not be able to provide the service requested. Qantas recommends that you visit `; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; if ((m = regex.exec(str)) !== null) { // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions