Regular Expressions 101

Save & Manage Regex

  • Current Version: 2
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"([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", flags=re.MULTILINE) test_str = ("1386551069\n" "1721125688\n" "871749537\n" "3410748801\n" "2935589455\n" "1885865030\n" "776296760\n" "614705581\n" "3841106923\n" "434616334\n" "1891651756\n" "1128215653\n" "256582433\n" "310780133\n" "3971028567\n" "2349690078\n" "489992769\n" "493183796\n" "3073937100\n" "3968540100\n" "777207799\n" "515453341\n" "487926468\n" "2597442171\n" "950819523\n" "1881247391\n" "3676486536\n" "3852572850\n" "3498953201\n" "2544525180\n" "297297258\n" "3783570310\n" "2485456860\n" "2866433205\n" "2638825384\n" "2405115019\n" "2734986756\n" "3237895121\n" "1560255677\n" "4228599165\n" "3106247743\n" "742719206\n" "2409129909\n" "3008020402\n" "328113612\n" "1081997633\n" "1583987616\n" "1029888552\n" "1375524867\n" "3913611859\n" "3488464791\n" "732377595\n" "431649729\n" "2105108903\n" "1454214821\n" "997975981\n" "1764756211\n" "2921737100\n" "754705833\n" "1823274447\n" "450215579\n" "976175934\n" "1991260870\n" "710069849\n\n" "28051484\n" "408224582\n" "1157838297\n" "3470985950\n" "1310525292\n" "2739928315\n" "3565721638\n" "3568607641\n" "3857889210\n" "682782262\n" "2845913801\n" "2625196544\n" "1036650602\n" "3890793110\n" "4276552453\n" "2017874229\n" "3935199786\n" "1136100076\n" "2406566087\n" "496970764\n" "2945538435\n" "2830207175\n" "4028712507\n" "2557754740\n" "572724662\n" "2854602512\n" "736902285\n" "3612716287\n" "2528051536\n" "3801506272\n" "164986382\n" "1757334153\n" "979200654\n" "1377646057\n" "1003603763\n" "4217274922\n" "3804763169\n" "2502416106\n" "698611315\n" "3586620445\n" "2343814657\n" "3220493083\n" "3505829324\n" "4268209107\n" "1798630324\n" "1932820146\n" "2356679271\n" "1883645842\n" "2495921085\n" "2912113431\n" "1519642783\n" "924263219\n" "3506109843\n" "2916121049\n" "4060307069\n" "1470129930\n" "4014068841\n" "1755190161\n" "311339709\n" "473039620\n" "2530217749\n" "1297591604\n" "3269125607\n" "2834128510") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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