Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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"
"
gm

Test String

Code Generator

Generated Code

import Foundation let pattern = #"([023]3|[067]0|[1289]1|5[5689]|67|96|88|77|65|05)$|^(8|4[358]|7[147]|51|37|30)|865|349|2.{5}5|761|74[348]|728|811|990"# let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) let testString = #""" 1386551069 1721125688 871749537 3410748801 2935589455 1885865030 776296760 614705581 3841106923 434616334 1891651756 1128215653 256582433 310780133 3971028567 2349690078 489992769 493183796 3073937100 3968540100 777207799 515453341 487926468 2597442171 950819523 1881247391 3676486536 3852572850 3498953201 2544525180 297297258 3783570310 2485456860 2866433205 2638825384 2405115019 2734986756 3237895121 1560255677 4228599165 3106247743 742719206 2409129909 3008020402 328113612 1081997633 1583987616 1029888552 1375524867 3913611859 3488464791 732377595 431649729 2105108903 1454214821 997975981 1764756211 2921737100 754705833 1823274447 450215579 976175934 1991260870 710069849 28051484 408224582 1157838297 3470985950 1310525292 2739928315 3565721638 3568607641 3857889210 682782262 2845913801 2625196544 1036650602 3890793110 4276552453 2017874229 3935199786 1136100076 2406566087 496970764 2945538435 2830207175 4028712507 2557754740 572724662 2854602512 736902285 3612716287 2528051536 3801506272 164986382 1757334153 979200654 1377646057 1003603763 4217274922 3804763169 2502416106 698611315 3586620445 2343814657 3220493083 3505829324 4268209107 1798630324 1932820146 2356679271 1883645842 2495921085 2912113431 1519642783 924263219 3506109843 2916121049 4060307069 1470129930 4014068841 1755190161 311339709 473039620 2530217749 1297591604 3269125607 2834128510 """# 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