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

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"\(stocks-to-watch\s+are\s+in\s+the\s+following\s+paragraph\):([\s\S]*?)Strong\svolume" test_str = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at sapien fermentum, (stocks-to-watch are in the following paragraph): \n" " \n" "SE e3/3, SAM e4/22, PYPL flag bo e5/6, LAD bo e4/22, GLOB RS72 e5/14, CCS bo e4/28, CRL RS 81 ATH e5/7, ENTG rbo \n" " PWR \n" "e4/21, CAMT 3wkbo e5/11, DAR TRbo e5/6, +TFII bo e4/21, GNRC ebo e4/30, bo e5/7, GPI bo e5/05, IESC bo e5/5, SNBR \n" "ABG , BOOT\n" "e4/22, SHYF e5/7, TBK bo>44.70 e4/21, Wflag bo e4/27 ENSG bo e5/11, >48.11 e5/20, ARCB >50 e5/5, +CSWI \n" " TTEC \n" "RS82 e5/20, ZBRA ebo RS83 e4/28, WD ebo bo>78.13 e5/6, RILY Mr156 e5/11, ETSY e4/30, UCTT >Mr34.59 e4/29, \n" "BKE ATKR e TPX \n" "e5/4, COPX Mr40.8, boATH e5/21, CAI >39.35 e5/5, NVMI bo e5/14, BRKS bo e4/30, SI ebo e4/29, 5/5, \n" "FOXF WAL \n" "RS85 ebo e4/30, BLOK, HZO e4/23, SIVB 2yr bo e4/22, PW bo e3/30, bo e5/6, HIBB >Mr68.31 e3/20, e7/17, TBBK \n" ", INMD SBNY\n" ">20.24 Mr30.49 e4/30, DKL RS78 e2/23, +XRT AVNW Mr99 e5/12, CROX e4/23, e5/6, SQ e5/6, HUBS e5/6, evol \n" "KLIC\n" "e7/21, TGH >26.5 Mr35.43 e5/4, bo e4/30, JLL >178.55 RS78 e4/29, AMRK Mr65.03 e4/27, CADE Mr28.66 e4/29, ON bo \n" "AGCO\n" "e5/9, CMBM e5/12, COWN Mr86.12 e4/29, CUBI Mr36.93 e5/4, AM Mr10.27 e4/29, ASO e5/28, MBIN e4/23, e4/29, DE \n" "DEN MTZ HVT\n" "e5/21, bo e5/18, e4/30, TSE Mr75.84 e5/6, BIG e5/29, CASH e4/22, EVR bo e4/22, e5/20, JOUT ATH e5/5, \n" "MVBF XPEL MX \n" " bo e4/28, RWJ na, VMI e4/22, WES Mr41.23 e5/5, EDUC e5/21, TVTY e5/6, bo e5/14, RVLV e5/13, + flag \n" "SNX ALLY DKS \n" "boe5/6, MYRG e4/29, e6/25, URI e4/29, VAC e5/6, WSM e5/28, e7/17, bo e6/2, RCKY e4/28, LPX e5/5, AN\n" "RH SLM FCNCA TX\n" "e4/20, bo e6/4, >18.13 e7/22, IMKTA e5/7, ABCB e4/23, AMAT e5/20, e4/28, ICHR e5/4, e4/27, RBNC \n" "LGIH CTRN\n" "e4/27, BLDR e4/30, e5/4, MHO e4/29, AMKR bo Mr65 e4/27, SKY e5/20, BZH e4/30, + e5/28, SGH Mathr56.69 \n" "SYX BECN YETI RM SAIA PAG\n" "e7/7, e4/28, Mr66.47 e5/7, boATH e5/13, IAC e4/28, e4/28, e4/28, ACBI e4/22, bo \n" "CHEF NWS GMS\n" "e4/28, Mr42.06 e4/28, LOB e4/21, e5/7, bo e6/25, GRBK lbbo Mr88 e5/11, LSCC bo e5/4, SBSW bo \n" "CBNK KNL OPY SEM SID TIPT\n" "e4/28, SF e4/30, bo e4/30, FIX e4/27, Mr27.26 e4/28, e5/1, e5/6, e4/28, >12.27 e5/7, \n" "ALGN ERII bo HWM e LOVE SSL STAA .\n" "( e4/28, e5/6, 5/6, e6/9, Mr 39.23 e4/28, e5/6 ) . Strong volume \n" "tends to lead price. Ut lorem ipsum, venenatis et aliquet in, suscipit sit amet tellus. Integer vestibulum luctus rhoncus. Proin at arcu mauris. Nam tempor ipsum quis commodo cursus. Aenean faucibus hendrerit aliquam. Curabitur ullamcorper, metus in volutpat pretium, diam purus laoreet diam, non pulvinar massa justo ac leo. Aenean vehicula, orci in rutrum sodales, neque nulla maximus purus, quis suscipit nulla nisi non nibh. Nunc a molestie nunc. Cras velit risus, eleifend ut aliquet rhoncus, ullamcorper non risus. Nam tristique facilisis purus, sed fringilla enim pulvinar vitae. Nunc dignissim consectetur molestie. Mauris id maximus lorem.\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html