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
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"\b540[^$](\s+\d{3,})", flags=re.MULTILINE) test_str = ("090323 0014 0006 0 506 120\n" "090323 0020 0008 0 100 506\n" "090323 0121 0001 0 506 540\n" "090323 0851 0002 0 550 315\n" "090323 0858 0004 0 600 540\n" "090323 0900 0009 0 100 170\n" "090323 0906 0002 0 500 530\n" "090323 0912 0005 9 888 6999 989888888888 7 001 0\n" "090323 0913 0006 9 888 140 989888888888 7 001 0\n" "090323 0922 0002 0 550 205\n" "090323 0927 0005 9 888 6999 989888888888 7 001 0\n" "090323 0928 0012 9 888 140 989888888888 7 001 0\n" "090323 0930 0004 0 550 120\n" "090323 0931 0021 9 888 120 989888888888 7 001 0\n" "090323 0937 0023 7 9 888 89888888888 150 7 010 4\n" "090323 0937 0005 9 888 6999 989888888888 7 001 0\n" "090323 0937 0000 0 100 130\n" "090323 0939 0022 9 888 140 989888888888 7 001 0\n" "090323 0939 0002 0 100 602\n" "090323 0942 0013 9 888 120 989888888888 7 001 0\n" "090323 0944 0009 9 888 120 989888888888 7 001 0\n" "090323 0944 0003 9 888 130 989888888888 7 001 0\n" "090323 0952 0007 9 888 6999 989888888888 7 001 0\n" "090323 1002 0041 9 888 120 989888888888 7 001 0\n" "090323 1005 0004 0 506 100\n" "090323 1013 0002 0 100 413\n" "090323 1015 0000 9 888 6999 989888888888 7 001 0\n" "090323 1017 0004 9 888 6999 989888888888 7 001 0\n" "090323 1018 0010 9 888 120 989888888888 7 001 0\n" "090323 1024 0001 0 130 140\n" "090323 1025 0004 0 500 130\n" "090323 1026 0005 0 530 500\n" "090323 1027 0036 7 9 888 89888888888 150 7 012 4\n" "090323 1028 0005 7 9 888 89888888888 150 7 013 4\n" "090323 1030 0019 9 888 120 989888888888 7 001 0\n" "090323 1037 0001 0 540 506\n" "090323 1037 0002 0 600 506\n" "090323 1041 0002 A 9 888 89888888888 173 3 016 4\n" "090323 1043 0052 9 888 120 988128888885 7 001 0\n" "090323 1043 0002 0 600 540\n" "090323 1045 0001 9 888 6999 989888888888 7 001 0\n" "090323 1045 0001 9 888 540 989888888888 7 001 0\n" "090323 1047 0005 7 888 5651 524 7 017 4\n" "090323 1047 0005 9 9 888 888 89888888888 9840 7 001 018 0\n" "090323 1048 0004 0 500 530\n" "090323 1106 0001 0 600 506\n" "090323 1118 0001 9 888 6999 989888888888 7 001 0\n" "090323 1118 0005 9 888 120 989888888888 7 001 0\n" "090323 1123 0003 0 540 506\n" "090323 1126 0001 7 9 888 89888888888 140 7 019 4\n" "090323 1127 0003 9 888 6999 988188888888 7 001 0\n" "090323 1128 0009 9 888 120 988188888888 7 001 0\n" "090323 1135 0003 0 533 100\n" "090323 1144 0004 0 533 100\n" "090323 1145 0000 7 9 888 89888888888 544 7 020 4\n" "090323 1146 0003 0 130 316\n" "090323 1147 0004 9 888 6999 989888888888 7 001 0\n" "090323 1147 0002 9 888 140 989888888888 7 001 0\n" "090323 1148 0002 0 550 120\n" "090323 1149 0007 7 9 888 89888888888 544 7 022 4\n" "090323 1149 0000 7 9 888 89888888888 514 7 023 4\n" "090323 1151 0006 9 888 6999 989888888888 7 001 0\n" "090323 1155 0043 9 888 120 989888888888 7 001 0\n" "090323 1157 0001 9 888 6999 989888888888 7 001 0\n" "090323 1158 0001 0 130 140\n" "090323 1158 0004 9 888 6999 989888888888 7 001 0\n" "090323 1159 0014 9 888 140 989888888888 7 001 0\n" "090323 1202 0005 0 100 314\n" "090323 1214 0002 0 100 310\n" "090323 1218 0005 7 9 888 89888888888 172 3 024 4\n" "090323 1222 0001 0 540 600\n" "090323 1222 0007 7 9 888 89888888888 172 3 025 4\n" "090323 1225 0010 9 888 120 989888888888 7 001 0\n" "090323 1228 0002 0 130 509\n" "090323 1229 0016 9 888 120 989888888888 7 001 0\n" "090323 1234 0003 0 100 544\n" "090323 1241 0015 7 9 888 89888888888 508 7 026 4\n" "090323 1242 0005 9 888 6999 989888888888 7 001 0\n" "090323 1243 0011 9 888 140 989888888888 7 001 0\n" "090323 1245 0018 0 100 208") 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