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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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 = #""" <p>(\s?]]><\/footer> <\/content>) """# let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) let testString = #""" <?xml version="1.0" encoding="utf-8"?> <content> <title /> <meta-description /> <meta-robots /> <heading1 /> <canonical /> <footer><![CDATA[ Anniston is a city undergoing a period of rebirth, with some of its buildings being refurbished while new real estate is also cropping up. Most of the city is still full of historic buildings which have been refurbished for use ranging from government offices to churches. </p><p></p><p>Situated on the slope of the Blue Mountain, it has a great climate which makes its environment friendly to different species of birds, mammals and reptiles. One can indulge in peaceful outdoor activities like bird watching, or hiking the Chief Ladiga Trail and the Silver Comet Trail as well as the Blue Ridges and the Appalachian Mountains.</p><p></p><p>This region has long been a cultural center for the northeastern part of Alabama. It&rsquo;s full of music, history, art and theatre. You can attend the annual Knox Concert Series which produces some of the best world-renowned music and dance productions. There is also a local theatre, the Community Actor&rsquo;s Studio Theatre, that not only puts on plays, musicals and skits with the help of local performers, but it also provides art education to local children for free. This is just a taste of what this city can offer in terms of entertainment and education. Some of the other well-established local entertainment venues include Wren&rsquo;s Nest and Your Local Art Studio.</p><p></p><p>This area has also a wide array of shopping malls including Quintard Mall and Oxford Exchange. Some of the other local shopping venues include major chains like Walgreens, Midtown Outlet and Fred&rsquo;s Store. Anniston has also some of the best restaurants that serve both local and international cuisines ranging from Italian, Chinese and even Japanese seafood.</p><p></p><p>Moreover, the city is also known for its historic museums which house aged artifacts, mummies and dioramas of wildlife. These museums include the Anniston Museum of Natural History as well as the Berman Museum of World History. Together they also provide a great avenue for learning about the rich history of this city.</p><p></p><p>As for getting in and around Anniston, the Anniston Eastern and Western bypass runs through city as well as a number of state routes and highways, making the city&rsquo;s transport system easy to navigate. So if you were thinking of relocating, Anniston, Alabama is a great place to be. Search our site to find your next home. </p><p></p><p> Top 1: [BrandRank1]</p><p>Top 2: [BrandRank2]</p><p> Top 3: [BrandRank3]</p><p> Average Plan Price [AveragePlanPrice]</p><p> Price Per Foot: [PricePerFoot]</p><p> ]]></footer> </content> """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let substitutionString = #"$1"# 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