Regular Expressions 101

Save & Share

  • Regex Version: ver. 12
  • 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
No Match

r"
"
gis

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 = "(?!letsgo\\.|shop\\.|advertise\\.|static\\.|www\\.)((\\w|-)+\\.)(tumblr\\.com|tmblr\\.co)\\/?(?!\\S)"; final String string = "Match the following:\n" + "https://dhabitahpunk-art.tumblr.com/\n" + "https://cdn.tumblr.com\n\n" + "DON'T match the following:\n" + "https://www.tumblr.com/todayontumblr\n" + "tumblr.com/todayontumblr\n" + "https://www.tumblr.com/todayontumblr/\n" + "tumblr.com/todayontumblr/\n" + "https://www.tumblr.com/dhabitahpunk-art\n" + "tumblr.com/dhabitahpunk-art\n" + "https://www.tumblr.com/dhabitahpunk-art/\n" + "tumblr.com/dhabitahpunk-art/\n" + "https://tmblr.co/MzB5rhaOrTp3uwB5NhcQsEw\n" + "https://www.tumblr.com/blog/view/grouper/\n" + "https://www.tumblr.com/internships\n" + "https://www.tumblr.com/transparency\n" + "https://www.tumblr.com/search/lana\n" + "https://www.tumblr.com/tagged/lwaxana%20troi?sort=top\n" + "https://www.tumblr.com/following\n" + "https://tumblr.com/customize/\n" + "https://letsgo.tumblr.com/\n" + "https://letsgo.tumblr.com/welcome-guide\n" + "https://64.media.tumblr.com/6c05087e5dbaccedf651d421148dfaa0/e7eb8d73a9a6cc70-8e/s540x810/e9cc402adacca3e983fc0448b94919b9f809c719.gifv\n" + "https://shop.tumblr.com/\n" + "https://shop.tumblr.com/new/\n" + "https://www.tumblr.com/tumblrmart/blue-checkmark\n" + "https://help.tumblr.com/hc/articles/115001572547\n" + "https://help.tumblr.com/hc\n" + "https://tumblr.com/help\n" + "https://api.tumblr.com/console\n" + "https://www.tumblr.com/oauth/apps\n" + "https://www.tumblr.com/api\n" + "https://assets.tumblr.com/downloads\n" + "https://www.tumblr.com/abuse\n" + "https://www.tumblr.com/themes/\n" + "https://www.tumblr.com/themes/tagged/two_column\n" + "https://www.tumblr.com/dmca\n" + "https://www.tumblr.com/docs/api_agreement\n" + "https://www.tumblr.com/account/delete\n" + "https://www.tumblr.com/settings\n" + "https://www.tumblr.com/settings/blog\n" + "https://www.tumblr.com/security\n" + "https://www.tumblr.com/developers\n" + "https://www.tumblr.com/press\n" + "https://www.tumblr.com/buttons\n" + "https://www.tumblr.com/logo\n" + "https://www.tumblr.com/tips\n" + "https://www.tumblr.com/support\n" + "https://www.tumblr.com/auth\n" + "https://www.tumblr.com/auth/google?redirectTo=undefined\n" + "https://www.tumblr.com/register\n" + "https://www.tumblr.com/register?source=new_to_tumblr\n" + "https://www.tumblr.com/login\n" + "https://www.tumblr.com/login?redirect_to=%2Fexplore%2Ftoday\n" + "https://www.tumblr.com/explore\n" + "https://www.tumblr.com/explore/trending\n" + "https://advertise.tumblr.com/\n" + "https://advertise.tumblr.com/#why\n" + "https://www.tumblr.com/jobs\n" + "https://www.tumblr.com/policy\n" + "https://www.tumblr.com/privacy_policy\n" + "https://www.tumblr.com/policy/privacy\n" + "https://www.tumblr.com/policy/terms-of-service\n" + "https://www.tumblr.com/apps\n" + "https://www.tumblr.com/about\n" + "https://about.tumblr.com/#quick-facts\n" + "https://www.tumblr.com/\n" + "https://www.tumblr.com/dhabitahpunk-art/tagged/Picturesque\n" + "tumblr.com/dhabitahpunk-art/tagged/Picturesque\n" + "tumblr.com\n" + "https://dhabitahpunk-art.tumblr.com/page/2\n" + "dhabitahpunk-art.tumblr.com/page\n" + "https://dhabitahpunk-art.tumblr.com/page/\n" + "https://dhabitahpunk-art.tumblr.com/commissions\n" + "https://dhabitahpunk-art.tumblr.com/post/714262490632044544/time-taken-355-hoursreference-unknown\n" + "https://static.tumblr.com/\n" + "https://static.tumblr.com/zyubucd/CIjopeea7/transparencyreport2016b.pdf"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); 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