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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

import Foundation let pattern = #"^"(.*)" (.*), (.*)"# let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) let testString = #""" Description "Mulligan" neutered male, Brindle Bullmastiff "Tiny" male, tan and white Boxer mix "Charlie" neutered male, black and white Labrador Retriever mix "Nala" spayed female, white and brown brindle Pit Bull mix "Lexie" female, white and black Pit Bull "Holly" Spayed female, white Labrador/Pitbull mix "Lincoln" male, fawn and white Pit Bull Terrier "Sparkles" spayed female, Brindle Plott Hound mix "Missy" Spayed Female, red/white Pitbull mix "Rita" female, brown Australian Shepherd "Miles Davis" female, gold/white Golden Retriever "Lacy" spayed female, Labrador Retriever Mix "Clementine" spayed female, black and white Austrailian Cattle dog "Coronel" Male, Tan/Black German Shepherd mix "Lady Bug" spayed female, white/black Pit bull/Jack Russell mix "Buddy" male, blue brindle and white Pitbull mix "Boomer" neutered brown Pit Bull Mix "Weezer" female, Tan/Brown German Shepherd "Little Girl" spayed female, brown brindle and white Bull Terrier "Diva" intact female, tri-color Pit Bull "Jack" neutered male, red/white Labrador Retriever mix "Salty" male, brown and white Boxer "G" male, brown Pit Bull/Boxer mix "Keely" spayed female, Red Labrador Retriever mix "Tyson" neutered male, German Shepherd "Tug" male, brown merle and white Queensland Heeler mix "Shebba" female, white Pit Bull mix "Blue" male, blue Pit Bull mix "Pinky" female, white Boxer mix "Ladybird" Spayed female, yellow brindle and white Pit Bull mix "Dozer" neutered male, white and red Rhodesian Ridgeback "Lahlo" spayed female, tan Boxer mix "Maya" spayed female, brown/white Pitbull mix "Cinnamon" female, red and white Border Collie "Taz" neutered male, brown brindle Boxer mix "Lily" female, black and white Chihuahua "Abbo" neutered male, white/brown Great Pyrenees mix "Milo" neutered male, white/brown, German Short-haired Pointer "Lia" spayed female, white/black Pit Bull/Jack Russell mix "Sissy" female, tan and black German Shepherd "Nippy" female, black and tan Shepherd mix "Ginger" spayed female, red and white American Fox Terrier mix "Jonah" female, brown and white Pit Bull mix "Diego" neutered male, cream and white Great Pyrenees "June" female, Brindle Pit Bull Terrier "Maia" female, white/tan Pit Bull mix "Iko" neutered male, Brown Brindle Catahoula mix "Zues" neutered male, blue and white Great Dane "Tank" neutered, black/grey German Wire-haired Pointer "Bumpy" neutered male, white and black Bull Terrier "Negro" neutered male, black, tan and white Chihuahua mix "Lucy" spayed female, brown brindle and white Boxer mix "Austin" male, red merle Australian Shepherd "Aries" spayed female, blue Cane Corso "Bella" spayed female, Tan and White Pit Bull mix "Gucio" male, black Giant Schnauzer "Kilo" neutered male, red and white Pit Bull mix "Chuy" spayed female, brown brindle and white Boxer mix "Flint" neutered male, blue Blue Lacy mix "Sydney" spayed female, Tricolor/Black Beagle "Sunny" Neutered Male, Brown/Tan Shepherd mix "Lucky" male, black and tri-colored Chihuahua "Cleo" female, black Labrador Retriever mix """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let substitutionString = #"$1\t$2\t$3"# let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString) 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