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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^\\s*(?<name>.+)\\scompleted"; final String string = " Michael just did their 5th workout! This is an\n" + "automated notification.\n" + "Do not reply to this email.\n\n\n" + " Michael just did their 5th workout!\n" + " Michael Montefusco completed BFR On-Ramp Lower Extremity and rated it as\n" + "RPE 4 / 10 (easy). Michael set 3 new personal bests.\n" + " View in Mobile App\n" + "<https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiTEFqSE1tZDFTMXlBd09ldUc1RlVQNDZaVS1BIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZhY3Rpb249b3Blbk1zZ1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ>\n" + " View in Web App\n" + "<https://mandrillapp.com/track/click/30003805/smartcuffsacademy.trainerize.com?p=eyJzIjoiZnJSQjFyd21YT2d1b19ZcVU3aWJHRFg3aGtnIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvc21hcnRjdWZmc2FjYWRlbXkudHJhaW5lcml6ZS5jb21cXFwvYXBwXFxcL1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ>\n" + "Download the iOS\n" + "<https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoianRsQ3VIM2x3UThJQWV1bkdmVHNoZGdFM3RVIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZtb2RlPWRvd25sb2FkSU9TXCIsXCJpZFwiOlwiZjMxZWZhZTU2N2YwNGE1OGI1NWM5MTM0YTVkMDRjODRcIixcInVybF9pZHNcIjpbXCIyZWIyYTVlMzM0MjQwMzNhNWFhZDUyZWExNjk0MWI0ODBjNzMwMGZmXCJdfSJ9>\n" + "or\n" + "Android\n" + "<https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiTWh6eE1WWGN0Y0hQQXRSOEM3dDY0a1F5T2prIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL29wZW5BcHAuYXNweD9ncm91cElEPTE1NDg1MiZtb2RlPWRvd25sb2FkQW5kcm9pZFwiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiMmViMmE1ZTMzNDI0MDMzYTVhYWQ1MmVhMTY5NDFiNDgwYzczMDBmZlwiXX0ifQ>\n" + "app. To receive this message in-app, via mail, or both, change your\n" + "notification settings through the mobile app.\n\n" + " Turn off email notifications\n" + "<https://mandrillapp.com/track/click/30003805/smartcuffsacademy.trainerize.com?p=eyJzIjoiY1dIOEwtb1QtT2g1Y2dtNnFsZFpsZjZSRU1FIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwczpcXFwvXFxcL3NtYXJ0Y3VmZnNhY2FkZW15LnRyYWluZXJpemUuY29tXFxcL2FwcFxcXC9wdWJsaWNcXFwvdW5zdWJzY3JpYmUuYXNweD90b2tlbj1TVEEwVVhwQmVVZHdlVEU1Vml0UFpsWTVaSE5uU1hsclFtZzBOR1p5Y0U0MSZ0eXBlPTBcIixcImlkXCI6XCJmMzFlZmFlNTY3ZjA0YTU4YjU1YzkxMzRhNWQwNGM4NFwiLFwidXJsX2lkc1wiOltcImMzZWM1NzVjMGFkM2M3YTk1NWMyYjFlMDg3ZDdmMTVkNjg1NmM0NDlcIl19In0>\n" + "for new messages\n" + " Powered by Trainerize\n" + "<https://mandrillapp.com/track/click/30003805/www.trainerize.com?p=eyJzIjoiQU1pY2h4VjJpTmd6ampXSXFrT1E5N3VDMmtZIiwidiI6MSwicCI6IntcInVcIjozMDAwMzgwNSxcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvd3d3LnRyYWluZXJpemUuY29tXFxcL1wiLFwiaWRcIjpcImYzMWVmYWU1NjdmMDRhNThiNTVjOTEzNGE1ZDA0Yzg0XCIsXCJ1cmxfaWRzXCI6W1wiYjU4NTgyYWJmYTM0NzQwNDliN2Q4ZDU2YzU1YjhmMWE2MWUwNzcwOVwiXX0ifQ>\n\n" + " *Copyright © 2020 Trainerize, All rights reserved.*"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html