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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

import Foundation let pattern = ##"(?mixu)^(?:(?!(|[!@#$%^&*123456789/';\";{}`~,.\[\]()_+=-])(price.?pr.?diction.?|it.?s.?running.?$|it.?[s]+.?coming|sq[u]+[e]+[z]+[e]+|n.?.?[g]+[e3yiu]+r|w.?.?[g]+[e3iuy]+.?r|ki[l1]+.?.?[your]+.?.?.?.?.?.?.?.?.?.?s[e3]+[l1]+f|k.?y.?s.?.?$|kill.*self|wa[l]+.?str[e3]+t.?b[e3]+[t]+[s]+|ava.?.?ab.?.?.?now|ch[e3]+.?.?[a]+p|co[m]+[e3]+nt|discount|^d.?m$|^d.?ms$|xclusive.?d[e3]+al|g[e]+t[t]+.?r[3e]+.?dy|^.?listed.?$|m[e3]+s[s]+[e3]+g.?.?.?$|[s]+[a]+[l]+[e3]+$|s[e3]+nd.?.?m[e3yi]+|shirt|of[f]+[3e]+r|w.?rr.?nty|is[s]+.?a.?bi[i]+[g]+.?wi[i]+n[n]+|arning.?.?r.?port|.?asy.?mon.?y|mass.?.?.?.?.?profits|hug.?.?.?.?gain|mass.?.?.?.?.?gain|bargain|mark.?t.?.?is.?.?b[o0]+min[n]+.?.?$|in.?xp.?nsiv.?.?$|giv.?away.?|r.?asonabl.?.?pric.?|affordab|und.?r.?val|c.?o.?n.?f.?.?d.?.?n.?t.?i.?a.?l|t[o0]+w[o0]+rk.?fr[o0]+m|fr[e3]+.?w[o0]+rk|^dd$|due.?diligence|i[s]+.?[f]+[i]+[r]+e|slingshot|[a]+[l]+.?t[i]+me|swung|stay.?away|bu[y]+.?.?.?.?h[o0]+[l]+[d]+|h[o0]+dl|h[o0]+[l]+[d]+.?[o0]+[n]+.?f[o0]+[r]+.?d[e3]+[a]+r.?l[i]+fe|^sus$|^highs$|b[e3]+f[o0]+r[e3]+.?[il1]+t[sz]+.?.?t[o0]+|^.?h[o0]ld[i]+[n]+g|h[e3]+dg|m[a]+[s]+[il1]+v.?.?d[i]+p|s.?[l]+[i1l]+n[g]+.?.?m[0o]+[n]+da[y]+|pati.?nt|pati.?nc.?|th[e3]+d[i]+p|sit.?back|njoy.?th[e3]+.?r[i]+d|l[e3]+ft.?b[ei]+h[i]+nd|st[a]+[y]+.?f[o]+cus|tak[i]+[n]+.?.?of[f]+|b[l]+[a]+[s]+[t]+.?.?.?.?o[f]+|major.?.?br[e3]+ak|to.?all.?th.?.?b[o0]+t|short.?s[e3]+[li1]+|g[o0]+.?t[o0]+.?[i]+[n]+[f]+[i1l]+[n]+[i1l]+[t]+[yei]+|no.?.?.?.?.?.?.?.?.?limit|difficult.?.?t[o0]+.?f[i1]+ll|d[o0]+uble.?d[o0]+wn|[o0]+ur.?tim.?.?|[i]+[s]+.?.?com[i]+[ng]+|stay.?str[o0]+ng|it[t's]+.?.?.?[s]+tart|[w]+[i]+[li1]+.?.?[n]+[o0]+[t]+.?[s]+[e3]+[li1]+.?|[j]+u[s]+[t]+.?[s]+t[a]+rt[e3]+d|l[li1]+f[e3]+.?chang|it.?.?.?a.?[s]+ign|st[o0]+nk|buy[il1]+ng.?.?m[o0]+re|p[i]+ck[i]+ng.?.?up|tak[il1]+ng.?.?[o0]+[f]+|w[e3].?d[e3]+[s]+[e3]+rv[e3]+.?[il1]+t|[k]+[i]+[c]+[k]+.?.?[o0]+[f]+|[o0]+ur.?fin.?st.?h[o0]+ur|^.?[a]+p[e]+$|^.?wsb$|r[i]+s[i]+ng.?[u]+p|^hf$|[a]+[l1i]+.?[you]+.?h[ave]+.?t[o0]+|bl[o0]+ck.?[o0]+ut.?th[e3]+.?|th.?y.?.?r.?.?.?scar.?d|sh[i1l]+[il1]+|r[ei1l]+ta[r]+d|bu[y]+.?bu[y]+|se[li1]+.?se[li1]+|a.?w[i]+[n]+[e3]+r|t[o0]+.th*[e3]+.m[o0]+n|b[o0]+th.?win|win.?win|hand.?$|i.?m.?.?.?s.?[li1]+[i]+n|i.?m.?buyin.?|buy.?.?.?.?.?.?d[i]+p|everyone.?.?.?.?buy|everyone.?.?.?.?sell|you.?.?.?.?sell|you.?.?.?.?.?.?buy|s.?ll.?.?.?.?off|mark.?t.?.?cap|punch.?.?.?.?thr[oe]+[uwe]+|who.?.?.?.?.?.?sell|who.?.?.?buy|if.?.?.?.?sell|if.?.?.?.?.?buy|[\u212f-\U000fffff]|[\u2000-\u211a])(|[!@#$%^&*/';\";{}123456789`~,.\[\]()_+=-]*)).)*$"## let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) let testString = #""# 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