Regular Expressions 101

Save & Manage Regex

  • Current Version: 5
  • 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?[6-9]|0)[12]?\d|2)?\d\.?\b){4}$", flags=re.MULTILINE) test_str = ("30.168.1.255.1\n" "127.1\n" "192.168.1.256\n" "-1.2.3.4\n" "1.1.1.1.\n" ".1.1.1.1\n" "01.1.1.1\n" "3...3\n" "1212.1.1.1\n" "2121.1.1.1\n" "0.0.0.0\n" "1.7.3.5\n" "2.14.6.10\n" "3.21.9.15\n" "4.28.12.20\n" "5.35.15.25\n" "6.42.18.30\n" "7.49.21.35\n" "8.56.24.40\n" "9.63.27.45\n" "10.70.30.50\n" "11.77.33.55\n" "12.84.36.60\n" "13.91.39.65\n" "14.98.42.70\n" "15.105.45.75\n" "16.112.48.80\n" "17.119.51.85\n" "18.126.54.90\n" "19.133.57.95\n" "20.140.60.100\n" "21.147.63.105\n" "22.154.66.110\n" "23.161.69.115\n" "24.168.72.120\n" "25.175.75.125\n" "26.182.78.130\n" "27.189.81.135\n" "28.196.84.140\n" "29.203.87.145\n" "30.210.90.150\n" "31.217.93.155\n" "32.224.96.160\n" "33.231.99.165\n" "34.238.102.170\n" "35.245.105.175\n" "36.252.108.180\n" "37.3.111.185\n" "38.10.114.190\n" "39.17.117.195\n" "40.24.120.200\n" "41.31.123.205\n" "42.38.126.210\n" "43.45.129.215\n" "44.52.132.220\n" "45.59.135.225\n" "46.66.138.230\n" "47.73.141.235\n" "48.80.144.240\n" "49.87.147.245\n" "50.94.150.250\n" "51.101.153.255\n" "52.108.156.4\n" "53.115.159.9\n" "54.122.162.14\n" "55.129.165.19\n" "56.136.168.24\n" "57.143.171.29\n" "58.150.174.34\n" "59.157.177.39\n" "60.164.180.44\n" "61.171.183.49\n" "62.178.186.54\n" "63.185.189.59\n" "64.192.192.64\n" "65.199.195.69\n" "66.206.198.74\n" "67.213.201.79\n" "68.220.204.84\n" "69.227.207.89\n" "70.234.210.94\n" "71.241.213.99\n" "72.248.216.104\n" "73.255.219.109\n" "74.6.222.114\n" "75.13.225.119\n" "76.20.228.124\n" "77.27.231.129\n" "78.34.234.134\n" "79.41.237.139\n" "80.48.240.144\n" "81.55.243.149\n" "82.62.246.154\n" "83.69.249.159\n" "84.76.252.164\n" "85.83.255.169\n" "86.90.2.174\n" "87.97.5.179\n" "88.104.8.184\n" "89.111.11.189\n" "90.118.14.194\n" "91.125.17.199\n" "92.132.20.204\n" "93.139.23.209\n" "94.146.26.214\n" "95.153.29.219\n" "96.160.32.224\n" "97.167.35.229\n" "98.174.38.234\n" "99.181.41.239\n" "100.188.44.244\n" "101.195.47.249\n" "102.202.50.254\n" "103.209.53.3\n" "104.216.56.8\n" "105.223.59.13\n" "106.230.62.18\n" "107.237.65.23\n" "108.244.68.28\n" "109.251.71.33\n" "110.2.74.38\n" "111.9.77.43\n" "112.16.80.48\n" "113.23.83.53\n" "114.30.86.58\n" "115.37.89.63\n" "116.44.92.68\n" "117.51.95.73\n" "118.58.98.78\n" "119.65.101.83\n" "120.72.104.88\n" "121.79.107.93\n" "122.86.110.98\n" "123.93.113.103\n" "124.100.116.108\n" "125.107.119.113\n" "126.114.122.118\n" "127.121.125.123\n" "128.128.128.128\n" "129.135.131.133\n" "130.142.134.138\n" "131.149.137.143\n" "132.156.140.148\n" "133.163.143.153\n" "134.170.146.158\n" "135.177.149.163\n" "136.184.152.168\n" "137.191.155.173\n" "138.198.158.178\n" "139.205.161.183\n" "140.212.164.188\n" "141.219.167.193\n" "142.226.170.198\n" "143.233.173.203\n" "144.240.176.208\n" "145.247.179.213\n" "146.254.182.218\n" "147.5.185.223\n" "148.12.188.228\n" "149.19.191.233\n" "150.26.194.238\n" "151.33.197.243\n" "152.40.200.248\n" "153.47.203.253\n" "154.54.206.2\n" "155.61.209.7\n" "156.68.212.12\n" "157.75.215.17\n" "158.82.218.22\n" "159.89.221.27\n" "160.96.224.32\n" "161.103.227.37\n" "162.110.230.42\n" "163.117.233.47\n" "164.124.236.52\n" "165.131.239.57\n" "166.138.242.62\n" "167.145.245.67\n" "168.152.248.72\n" "169.159.251.77\n" "170.166.254.82\n" "171.173.1.87\n" "172.180.4.92\n" "173.187.7.97\n" "174.194.10.102\n" "175.201.13.107\n" "176.208.16.112\n" "177.215.19.117\n" "178.222.22.122\n" "179.229.25.127\n" "180.236.28.132\n" "181.243.31.137\n" "182.250.34.142\n" "183.1.37.147\n" "184.8.40.152\n" "185.15.43.157\n" "186.22.46.162\n" "187.29.49.167\n" "188.36.52.172\n" "189.43.55.177\n" "190.50.58.182\n" "191.57.61.187\n" "192.64.64.192\n" "193.71.67.197\n" "194.78.70.202\n" "195.85.73.207\n" "196.92.76.212\n" "197.99.79.217\n" "198.106.82.222\n" "199.113.85.227\n" "200.120.88.232\n" "201.127.91.237\n" "202.134.94.242\n" "203.141.97.247\n" "204.148.100.252\n" "205.155.103.1\n" "206.162.106.6\n" "207.169.109.11\n" "208.176.112.16\n" "209.183.115.21\n" "210.190.118.26\n" "211.197.121.31\n" "212.204.124.36\n" "213.211.127.41\n" "214.218.130.46\n" "215.225.133.51\n" "216.232.136.56\n" "217.239.139.61\n" "218.246.142.66\n" "219.253.145.71\n" "220.4.148.76\n" "221.11.151.81\n" "222.18.154.86\n" "223.25.157.91\n" "224.32.160.96\n" "225.39.163.101\n" "226.46.166.106\n" "227.53.169.111\n" "228.60.172.116\n" "229.67.175.121\n" "230.74.178.126\n" "231.81.181.131\n" "232.88.184.136\n" "233.95.187.141\n" "234.102.190.146\n" "235.109.193.151\n" "236.116.196.156\n" "237.123.199.161\n" "238.130.202.166\n" "239.137.205.171\n" "240.144.208.176\n" "241.151.211.181\n" "242.158.214.186\n" "243.165.217.191\n" "244.172.220.196\n" "245.179.223.201\n" "246.186.226.206\n" "247.193.229.211\n" "248.200.232.216\n" "249.207.235.221\n" "250.214.238.226\n" "251.221.241.231\n" "252.228.244.236\n" "253.235.247.241\n" "254.242.250.246\n" "255.249.253.251\n" "256.0.0.0\n" "1.257.1.1\n" "2.2.258.2\n" "3.3.3.259\n" "260.4.4.4\n" "5.261.5.5\n" "6.6.262.6\n" "7.7.7.263\n" "264.8.8.8\n" "9.265.9.9\n" "10.10.266.10\n" "11.11.11.267\n" "268.12.12.12\n" "13.269.13.13\n" "14.14.270.14\n" "15.15.15.271\n" "272.0.0.0\n" "1.273.1.1\n" "2.2.274.2\n" "3.3.3.275\n" "276.4.4.4\n" "5.277.5.5\n" "6.6.278.6\n" "7.7.7.279\n" "280.8.8.8\n" "9.281.9.9\n" "10.10.282.10\n" "11.11.11.283\n" "284.12.12.12\n" "13.285.13.13\n" "14.14.286.14\n" "15.15.15.287\n" "288.0.0.0\n" "1.289.1.1\n" "2.2.290.2\n" "3.3.3.291\n" "292.4.4.4\n" "5.293.5.5\n" "6.6.294.6\n" "7.7.7.295\n" "296.8.8.8\n" "9.297.9.9\n" "10.10.298.10\n" "11.11.11.299\n" "300.12.12.12\n" "13.301.13.13\n" "14.14.302.14\n" "15.15.15.303\n" "304.0.0.0\n" "1.305.1.1\n" "2.2.306.2\n" "3.3.3.307\n" "308.4.4.4\n" "5.309.5.5\n" "6.6.310.6\n" "7.7.7.311\n" "312.8.8.8\n" "9.313.9.9\n" "10.10.314.10\n" "11.11.11.315\n" "316.12.12.12\n" "13.317.13.13\n" "14.14.318.14\n" "15.15.15.319") 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