Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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 = '/^\s*(?<name>.+)\scompleted/m'; $str = ' Michael just did their 5th workout! This is an automated notification. Do not reply to this email. Michael just did their 5th workout! Michael Montefusco completed BFR On-Ramp Lower Extremity and rated it as RPE 4 / 10 (easy). Michael set 3 new personal bests. View in Mobile App <https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiTEFqSE1tZDFTMXlBd09ldUc1RlVQNDZaVS1BIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZhY3Rpb249b3Blbk1zZ1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ> View in Web App <https://mandrillapp.com/track/click/30003805/smartcuffsacademy.trainerize.com?p=eyJzIjoiZnJSQjFyd21YT2d1b19ZcVU3aWJHRFg3aGtnIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvc21hcnRjdWZmc2FjYWRlbXkudHJhaW5lcml6ZS5jb21cXFwvYXBwXFxcL1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ> Download the iOS <https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoianRsQ3VIM2x3UThJQWV1bkdmVHNoZGdFM3RVIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZtb2RlPWRvd25sb2FkSU9TXCIsXCJpZFwiOlwiZjMxZWZhZTU2N2YwNGE1OGI1NWM5MTM0YTVkMDRjODRcIixcInVybF9pZHNcIjpbXCIyZWIyYTVlMzM0MjQwMzNhNWFhZDUyZWExNjk0MWI0ODBjNzMwMGZmXCJdfSJ9> or Android <https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiTWh6eE1WWGN0Y0hQQXRSOEM3dDY0a1F5T2prIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZtb2RlPWRvd25sb2FkQW5kcm9pZFwiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ> app. To receive this message in-app, via mail, or both, change your notification settings through the mobile app. Turn off email notifications <https://mandrillapp.com/track/click/30003805/smartcuffsacademy.trainerize.com?p=eyJzIjoiY1dIOEwtb1QtT2g1Y2dtNnFsZFpsZjZSRU1FIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwczpcXFwvXFxcL3NtYXJ0Y3VmZnNhY2FkZW15LnRyYWluZXJpemUuY29tXFxcL2FwcFxcXC9wdWJsaWNcXFwvdW5zdWJzY3JpYmUuYXNweD90b2tlbj1TVEEwVVhwQmVVZHdlVEU1Vml0UFpsWTVaSE5uU1hsclFtZzBOR1p5Y0U0MSZ0eXBlPTBcIixcImlkXCI6XCJmMzFlZmFlNTY3ZjA0YTU4YjU1YzkxMzRhNWQwNGM4NFwiLFwidXJsX2lkc1wiOltcImMzZWM1NzVjMGFkM2M3YTk1NWMyYjFlMDg3ZDdmMTVkNjg1NmM0NDlcIl19In0> for new messages Powered by Trainerize <https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiQU1pY2h4VjJpTmd6ampXSXFrT1E5N3VDMmtZIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiYjU4NTgyYWJmYTM0NzQwNDliN2Q4ZDU2YzU1YjhmMWE2MWUwNzcwOVwiXX0ifQ> *Copyright © 2020 Trainerize, All rights reserved.*'; 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