Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

import Foundation let pattern = #"<\/?(\d)"# let regex = try! NSRegularExpression(pattern: pattern) let testString = #""" <?xml version="1.0"?> <data> <client_name>Awesome Client</client_name> <account_number/> <date_created>02/12/2016</date_created> <form_number>4126</form_number> <customer_po/> <terms_name>Credit Card</terms_name> <date_shipped>12/31/1969</date_shipped> <billing_contact_email/> <billing_contact_address_line_1/> <billing_contact_address_line_2/> <billing_contact_address_line_3/> <billing_contact_address_line_4/> <billing_contact_address_city/> <billing_contact_address_state>British Columbia</billing_contact_address_state> <billing_contact_address_postal/> <billing_contact_address_country>Canada</billing_contact_address_country> <shipping_contact_address_line_1/> <shipping_contact_address_line_2/> <shipping_contact_address_line_3/> <shipping_contact_address_line_4/> <shipping_contact_address_city/> <shipping_contact_address_state>British Columbia</shipping_contact_address_state> <shipping_contact_address_postal/> <shipping_contact_address_country>Canada</shipping_contact_address_country> <billing_contact_first_name>another</billing_contact_first_name> <billing_contact_last_name>client</billing_contact_last_name> <client_rep_full_name>Rob Montebelli</client_rep_full_name> <order_rep_full_name>Mark Graham</order_rep_full_name> <job_name>77777</job_name> <job_number>2620</job_number> <event_type>Donor Gift</event_type> <due_date>02/12/2016</due_date> <shipping_method/> <currency>CAD</currency> <total_taxes>0.00</total_taxes> <total_subtotal>1,760.16</total_subtotal> <total>1,760.16</total> <items> <item0> <taxes> <0>E</0> </taxes> <title>1889-24</title> <quantity>6</quantity> <description>Carhartt (R) Signature Utility Duffel; TBD TBD</description> <unit_price>159.32</unit_price> </item0> <item1> <taxes> <0>E</0> </taxes> <title>0022-56</title> <quantity>12</quantity> <description>Zoom (TM) DayTripper Sling Compu-Messenger; TBD TBD</description> <unit_price>67.02</unit_price> </item1> </items> </data> """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let substitutionString = #"<number$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