Regular Expressions 101

Save & Share

  • Regex Version: ver. 8
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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 = '/(?<! - )((?:Jul|Aug)\W\d+\W+\d+)(?!.*(?:Jul|Aug)\W\d+\W+\d+)/m'; $str = 'Jul 31, 2015 - Aug 27, 2015   |   Itinerary # 1110473023685       Amman (AMM) ? Chicago (ORD) Jul 31, 2015 - Aug 27, 2015 , 1 round trip ticket   NOT BOOKED This flight is not booked. Book now to guarantee price and availability. Traveler Information Adult No frequent flyer details provided * Seat assignments, special meals, frequent flyer point awards and special assistance requests should be confirmed directly with the airline. Jul 31, 2015 - Departure 2 stops Total travel time:20 h 40 m Amman Paris 5 h 0 m 2,097 mi AMM  1:30am CDG  5:30am   Terminal 2E   Airport check-in with Air France Delta  8429 Operated by Air France Economy / Coach (B) aris Amsterdam 1 h 15 m 247 mi CDG  8:45am Terminal 2F AMS  10:00am     Delta  9429 Operated by KLM Economy / Coach (B) | Confirm seats with the airline * Layover: 2 h 40 m Amsterdam Chicago 8 h 30 m 4,112 mi AMS  12:40pm ORD  2:10pm   Terminal 5   Delta  9382 Operated by KLM Economy / Coach (B) | Confirm seats with the airline * Aug 26, 2015 - Return 1 stop Total travel time:19 h 0 m Chicago Paris 8 h 15 m 4,148 mi ORD  5:20pm Terminal 5 CDG  8:35am +1 day   Terminal 2E   Air France  489 Economy / Coach (N) | Confirm seats with the airline * Layover: 6 h 10 m Paris Amman 4 h 35 m 2,097 mi CDG  2:45pm Terminal 2E AMM  8:20pm   (Arrives on Aug 27, 2015)   Air France  3840 Economy / Coach (N) | Confirm seats with the airline * Airline Rules & Regulations ·         This price includes a nonrefundable booking fee. ·         We understand that sometimes plans change. We do not charge a cancel or change fee. When the airline charges such fees in accordance with its own polic ies, the cost will be passed on to you. ·  nonstop Price Summary Traveler 1: Adult   $1,901.20 Flight   $1,267.00 Taxes & Fees   $634.20 Expedia Booking Fee   $7.00 Total: $1,908.20 All prices quoted in US dollars.     '; 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