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

/
/

Test String

Code Generator

Generated Code

re = /Order Total:\nCDN\$ ([\d\.]+)/ str = '---------- Forwarded message ---------- From: auto-confirm@amazon.ca <auto-confirm@amazon.ca> Date: Fri, Nov 6, 2015 at 11:24 AM Subject: Your Amazon.ca order of "Cheetah Mounts ALAMLB..." To: Charles Regan <charles.regan@gmail.com> Amazon.ca Your Orders | Your Account | Amazon.ca Order Confirmation Order #701-7756830-8577864 Hello Charles Regan, Thank you for shopping with us. We’ll send a confirmation once your item has shipped. Your order details are indicated below. If you would like to view the status of your order or make any changes to it, please visit Your Orders on Amazon.ca. Your estimated delivery date is: Wednesday, November 18, 2015 Your shipping speed: FREE Shipping Your Orders Your order will be sent to: CHARLES REGAN 1419 CH. DE L\'ETANG-DU-NORD ETANG-DU-NORD, Québec G4T3B9 Canada Order Details Order #701-7756830-8577864 Placed on Friday, November 6, 2015 Cheetah Mounts ALAMLB Articulating Arm (20" Extension) TV Wall Mount Bracket for 23-49 inch LCD, LED and Plasma Flat Screen TVs up to VESA 400x400 and 66lbs, with full Ballhead Tilt, Swivel, and Rotation Motion, Including a Twisted Veins 10\' Braided High Speed with Ethernet HDMI Cable and a 6" 3-Axis Magnetic Bubble Level Electronics Sold by SPN Imports and Services Condition: New Facebook Twitter Pinterest CDN$ 29.33 Item Subtotal: CDN$ 29.33 Shipping & Handling: CDN$ 0.00 Estimated Tax (GST/HST): CDN$ 0.00 Estimated Tax (PST/QST): CDN$ 0.00 Order Total: CDN$ 29.33 To learn more about ordering, go to Ordering from Amazon.ca. If you want more information or need more assistance, go to Help. We hope to see you again soon! Amazon.ca This email was sent from a notification-only address that cannot accept incoming email. Please do not reply to this message. Amazon.ca Vos commandes | Votre compte | Amazon.ca Confirmation de la commande Commande n° 701-7756830-8577864 Bonjour Charles Regan, Merci d\'avoir magasiné chez nous. Nous vous enverrons une confirmation une fois que votre article aura été expédié. Les détails de votre commande sont indiqués ci-dessous. Veuillez visiter la section Vos commandes sur Amazon.ca si vous souhaitez voir le statut de votre commande ou apporter des modifications à celle-ci. Votre date de livraison prévue est le : mercredi 18 novembre 2015 Votre mode de livraison : Livraison GRATUITE Your Orders Votre commande sera expédiée à : CHARLES REGAN 1419 CH. DE L\'ETANG-DU-NORD ETANG-DU-NORD, Québec G4T3B9 Canada Détails de la commande Commande n° 701-7756830-8577864 Passée le vendredi 6 novembre 2015 Cheetah Mounts ALAMLB Articulating Arm (20" Extension) TV Wall Mount Bracket for 23-49 inch LCD, LED and Plasma Flat Screen TVs up to VESA 400x400 and 66lbs, with full Ballhead Tilt, Swivel, and Rotation Motion, Including a Twisted Veins 10\' Braided High Speed with Ethernet HDMI Cable and a 6" 3-Axis Magnetic Bubble Level Electronics Vendu par SPN Imports and Services Condition : New Facebook Twitter Pinterest CDN$ 29.33 Sous-total article(s) : CDN$ 29.33 Expédition et manutention : CDN$ 0.00 Estimation de la TPS/TVH : CDN$ 0.00 Estimation de la TVP/TVQ : CDN$ 0.00 Total de la commande : CDN$ 29.33 Pour en apprendre davantage à propos des commandes, consultez la page Commander sur Amazon.ca. Si vous souhaitez obtenir de plus amples informations ou si vous avez besoin d\'assistance, consultez nos pages d\'aide. Nous espérons vous revoir bientôt. Amazon.ca Ce courriel a été envoyé à partir d\'une adresse de notification uniquement qui ne peut recevoir de courriels entrants. Veuillez ne pas répondre à ce message.' # Print the match result str.match(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html