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

/
/
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 = "[0-9]"; final String string = "WEBVTT\n\n" + "NOTE duration:\"02:09:15.8840000\"\n\n" + "NOTE language:en-us\n\n" + "NOTE Confidence: 0.881069481372833\n\n" + "d8d8fcb9-ccb1-41f2-a75e-0c3088e95dc2\n" + "00:00:01.720 --> 00:00:07.798\n" + "So we're going\n" + "to try to\n\n" + "NOTE Confidence: 0.881069481372833\n\n" + "a8f8cc83-48c4-4acc-881b-85b37c73b42c\n" + "00:00:07.798 --> 00:00:13.876\n" + "to use Microsoft\n" + "Teams next week,\n\n" + "NOTE Confidence: 0.881069481372833\n\n" + "d2738b5d-b7ee-4b58-8388-4b7524c3c563\n" + "00:00:13.876 --> 00:00:19.954\n" + "so will post\n" + "it as a\n\n" + "NOTE Confidence: 0.802268326282501\n\n" + "baab9c8e-f018-48a2-a355-b23eb29174e9\n" + "00:00:19.954 --> 00:00:25.728\n" + "teams meeting. If you've never\n" + "used prosoft teams before, it's\n\n" + "NOTE Confidence: 0.932209372520447\n\n" + "73231caa-7ae7-4046-acdf-c6691c7c3c41\n" + "00:00:25.728 --> 00:00:30.013\n" + "it's. Basically the same thing,\n" + "just a little more stable.\n\n" + "NOTE Confidence: 0.825244784355164\n\n" + "3ab6c4cb-9d70-4140-8356-c0f7c2316874\n" + "00:00:30.730 --> 00:00:35.224\n" + "Then they will put the link in\n" + "Quercus and send it out as an"; 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