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

/
/
g

Test String

Code Generator

Generated Code

import Foundation let pattern = #"class=\"(.*?)\""# let regex = try! NSRegularExpression(pattern: pattern) let testString = ##""" Xem thêm</a></div></div></div></div><div class="em en eo ep eq"><a href="/groups/720798081668729bacr=1591362312%3A1008883346193533%3A1008883346193533%2C0%2C0%3A7%3AKw%3D%3D&amp;multi_permalinks&amp;refid=18"><span>Xem thêm bài viết</span></a></div></div><a name="groupMenuBottom"></a><div class="er"><h3 class="es">Menu nhóm</h3><ul class="bz et"><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=about&amp;refid=18">Giới thiệu</a></td><td class="n"></td></tr></tbody></table></li><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=info&amp;refid=18">Thông tin</a></td><td class="n"></td></tr></tbody></table></li><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=members&amp;refid=18" id="u_0_3">Thành viên</a></td><td class="n"><span class="eu cu" id="u_0_2">239</span></td></tr></tbody></table></li><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=photos&amp;refid=18" id="u_0_7">Ảnh</a></td><td class="n"><span class="eu cu" id="u_0_6">1928</span></td></tr></tbody></table></li><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=events&amp;refid=18">Sự kiện</a></td><td class="n"></td></tr></tbody></table></li><li class="du"><table class="m bl"><tbody><tr><td class="t"><a href="/groups/720798081668729?view=files&amp;refid=18">File</a></td><td class="n"></td></tr></tbody></table></li></ul></div><div class="ev" style="display:none"><div class="ew"><div class="ex"><img src="https://static.xx.fbcdn.net/rsrc.php/v3/yR/r/CjVACNCmi_H.png" width="54" height="24" class="ey ez s" /><div class="fa"><div class="fb"><a href="#" class="bt fc bv">Xem dòng thời gian</a><a href="#" class="bt fc bv">Thêm vào nhóm</a><a href="#" class="bt fc bv">Mời tham gia sự kiện</a></div></div></div></div></div></div><div style="display:none"></div></div></div><div class="bz"><div class="fd"><div class="fe"><table class="m"><tbody><tr><td class="t ff" style="width:50%"><b class="fg">Tiếng Việt</b><a class="fh" href="/a/language.php? """## 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