Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • 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
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"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", flags=re.MULTILINE) test_str = ("\n" "Canada , Toronto\n" "IP: 104.166.127.78\n" "IPv6: 2605:e440:6::71\n" "http://104.166.127.78/1000MB.test\n" "http://[2605:e440:6::71]/1000MB.test\n\n" "China , Hong Kong\n" "IP: 91.149.237.213\n" "IPv6: 2605:e440:15::2:7b\n" "http://91.149.237.213/1000MB.test\n" "http://[2605:e440:15::2:7b]/1000MB.test\n\n" "Finland , Helsinki\n" "IP: 91.149.255.106\n" "IPv6: 2605:e440:7::63\n" "http://91.149.255.106/1000MB.test\n" "http://[2605:e440:7::63]/1000MB.test\n\n" "France , Paris\n" "IP: 185.143.222.48\n" "IPv6: 2605:e440:9::3:20\n" "http://185.143.222.48/1000MB.test\n" "http://[2605:e440:9::3:20]/1000MB.test\n\n" "Germany , Frankfurt\n" "IP: 91.149.223.204\n" "IPv6: 2605:e440:1::1:14a\n" "http://91.149.223.204/1000MB.test\n" "http://[2605:e440:1::1:14a]/1000MB.test\n\n" "Italy , Palermo\n" "IP: 194.87.47.32\n" "IPv6: 2605:e440:12::2:16\n" "http://194.87.47.32/1000MB.test\n" "http://[2605:e440:12::2:16]/1000MB.test\n\n" "Latvia , Riga\n" "IP: 194.58.34.42\n" "IPv6: 2605:e440:13::20\n" "http://194.58.34.42/1000MB.test\n" "http://[2605:e440:13::20]/1000MB.test\n\n" "Netherlands , Amsterdam\n" "IP: 91.149.241.62\n" "IPv6: 2605:e440:2::2e\n" "http://91.149.241.62/1000MB.test\n" "http://[2605:e440:2::2e]/1000MB.test\n\n" "Poland , Warsaw\n" "IP: 91.149.253.58\n" "IPv6: 2605:e440:4::2:1f\n" "http://91.149.253.58/1000MB.test\n" "http://[2605:e440:4::2:1f]/1000MB.test\n\n" "Russia , Novosibirsk, TTK\n" "IP: 193.38.50.142\n" "IPv6: 2a00:b700:4::1:291\n" "http://193.38.50.142/50MB.test\n" "http://[2a00:b700:4::1:291]/50MB.test\n\n" "Russia , Novosibirsk, Rostelecom\n" "IP: 46.29.162.89\n" "IPv6: 2a00:b700:4:0:6463:23ff:fe8e:7335\n" "http://46.29.162.89/50MB.test\n" "http://[2a00:b700:4:0:6463:23ff:fe8e:7335]/50MB.test\n\n" "Russia , Kazan\n" "IP: 176.32.32.133\n" "IPv6: 2a00:b700:1::f7\n" "http://176.32.32.133/50MB.test\n" "http://[2a00:b700:1::f7]/50MB.test\n\n" "Russia , Saint Petersburg\n" "IP: 194.87.68.192\n" "IPv6: 2a00:b700:5::5:33c\n" "http://194.87.68.192/50MB.test\n" "http://[2a00:b700:5::5:33c]/50MB.test\n\n" "Russia , Moscow, Fiord\n" "IP: 212.60.5.88\n" "IPv6: 2a00:b700:3::5:3e4\n" "http://212.60.5.88/50MB.test\n" "http://[2a00:b700:3::5:3e4]/50MB.test\n\n" "Russia , Moscow, DataLine\n" "IP: 46.17.40.85\n" "IPv6: 2a00:b700::d:75\n" "http://46.17.40.85/50MB.test\n" "http://[2a00:b700::d:75]/50MB.test\n\n" "Spain , Madrid\n" "IP: 91.149.242.38\n" "IPv6: 2605:e440:3::2:18\n" "http://91.149.242.38/1000MB.test\n" "http://[2605:e440:3::2:18]/1000MB.test\n\n" "USA , Dallas\n" "IP: 209.209.112.37\n" "IPv6: 2605:e440::5:5\n" "http://209.209.112.37/50MB.test\n" "http://[2605:e440::5:5]/50MB.test\n\n" "USA , Los-Angeles\n" "IP: 155.254.192.138\n" "IPv6: 2605:e440:5::2:118\n" "http://155.254.192.138/1000MB.test\n" "http://[2605:e440:5::2:118]/1000MB.test\n\n" "USA , Atlanta\n" "IP: 134.195.96.22\n" "IPv6: 2605:e440:14::3:d\n" "http://134.195.96.22/1000MB.test\n" "http://[2605:e440:14::3:d]/1000MB.test\n\n" "Ukraine , Kiev\n" "IP: 194.87.189.8\n" "IPv6: 2605:e440:10::2:4\n" "http://194.87.189.8/1000MB.test\n" "http://[2605:e440:10::2:4]/1000MB.test\n\n" "United Kingdom , London\n" "IP: 91.149.202.91\n" "IPv6: 2605:e440:8::2:1b\n" "http://91.149.202.91/1000MB.test\n" "http://[2605:e440:8::2:1b]/1000MB.test") 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