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 Foundation let pattern = #"(?!letsgo\.|shop\.|advertise\.|static\.|www\.)((\w|-)+\.)(tumblr\.com|tmblr\.co)\/?(?!\S)"# let regex = try! NSRegularExpression(pattern: pattern, options: [.caseInsensitive, .dotMatchesLineSeparators]) let testString = ##""" Match the following: https://dhabitahpunk-art.tumblr.com/ https://cdn.tumblr.com DON'T match the following: https://www.tumblr.com/todayontumblr tumblr.com/todayontumblr https://www.tumblr.com/todayontumblr/ tumblr.com/todayontumblr/ https://www.tumblr.com/dhabitahpunk-art tumblr.com/dhabitahpunk-art https://www.tumblr.com/dhabitahpunk-art/ tumblr.com/dhabitahpunk-art/ https://tmblr.co/MzB5rhaOrTp3uwB5NhcQsEw https://www.tumblr.com/blog/view/grouper/ https://www.tumblr.com/internships https://www.tumblr.com/transparency https://www.tumblr.com/search/lana https://www.tumblr.com/tagged/lwaxana%20troi?sort=top https://www.tumblr.com/following https://tumblr.com/customize/ https://letsgo.tumblr.com/ https://letsgo.tumblr.com/welcome-guide https://64.media.tumblr.com/6c05087e5dbaccedf651d421148dfaa0/e7eb8d73a9a6cc70-8e/s540x810/e9cc402adacca3e983fc0448b94919b9f809c719.gifv https://shop.tumblr.com/ https://shop.tumblr.com/new/ https://www.tumblr.com/tumblrmart/blue-checkmark https://help.tumblr.com/hc/articles/115001572547 https://help.tumblr.com/hc https://tumblr.com/help https://api.tumblr.com/console https://www.tumblr.com/oauth/apps https://www.tumblr.com/api https://assets.tumblr.com/downloads https://www.tumblr.com/abuse https://www.tumblr.com/themes/ https://www.tumblr.com/themes/tagged/two_column https://www.tumblr.com/dmca https://www.tumblr.com/docs/api_agreement https://www.tumblr.com/account/delete https://www.tumblr.com/settings https://www.tumblr.com/settings/blog https://www.tumblr.com/security https://www.tumblr.com/developers https://www.tumblr.com/press https://www.tumblr.com/buttons https://www.tumblr.com/logo https://www.tumblr.com/tips https://www.tumblr.com/support https://www.tumblr.com/auth https://www.tumblr.com/auth/google?redirectTo=undefined https://www.tumblr.com/register https://www.tumblr.com/register?source=new_to_tumblr https://www.tumblr.com/login https://www.tumblr.com/login?redirect_to=%2Fexplore%2Ftoday https://www.tumblr.com/explore https://www.tumblr.com/explore/trending https://advertise.tumblr.com/ https://advertise.tumblr.com/#why https://www.tumblr.com/jobs https://www.tumblr.com/policy https://www.tumblr.com/privacy_policy https://www.tumblr.com/policy/privacy https://www.tumblr.com/policy/terms-of-service https://www.tumblr.com/apps https://www.tumblr.com/about https://about.tumblr.com/#quick-facts https://www.tumblr.com/ https://www.tumblr.com/dhabitahpunk-art/tagged/Picturesque tumblr.com/dhabitahpunk-art/tagged/Picturesque tumblr.com https://dhabitahpunk-art.tumblr.com/page/2 dhabitahpunk-art.tumblr.com/page https://dhabitahpunk-art.tumblr.com/page/ https://dhabitahpunk-art.tumblr.com/commissions https://dhabitahpunk-art.tumblr.com/post/714262490632044544/time-taken-355-hoursreference-unknown https://static.tumblr.com/ https://static.tumblr.com/zyubucd/CIjopeea7/transparencyreport2016b.pdf """## let stringRange = NSRange(location: 0, length: testString.utf16.count) let matches = regex.matches(in: testString, range: stringRange) var result: [[String]] = [] for match in matches { var groups: [String] = [] for rangeIndex in 1 ..< match.numberOfRanges { let nsRange = match.range(at: rangeIndex) guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue } let string = (testString as NSString).substring(with: nsRange) groups.append(string) } if !groups.isEmpty { result.append(groups) } } print(result)

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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression