Regular Expressions 101

Save & Share

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

/
/
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"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):\d*" test_str = ("10.0.1.101:80 open\n" "10.0.1.52:22 open\n" "10.0.1.190:80 open\n" "10.0.1.241:80 open\n" "10.0.1.103:22 open\n" "10.0.1.242:135 open\n" "10.0.1.241:135 open\n" "10.0.1.110:22 open\n" "10.0.1.1:22 open\n" "10.0.1.218:80 open\n" "10.0.1.221:135 open\n" "10.0.1.197:22 open\n" "10.0.1.212:80 open\n" "10.0.1.214:22 open\n" "10.0.1.211:80 open\n" "10.0.1.101:445 open\n" "10.0.1.52:80 open\n" "10.0.1.241:445 open\n" "10.0.1.86:80 open\n" "10.0.1.241:1433 open\n" "10.0.1.217:80 open\n" "10.0.1.101:8000 open\n" "10.0.1.86:1433 open\n" "10.0.1.101:443 open\n" "10.0.1.106:135 open\n" "10.0.1.115:443 open\n" "10.0.1.220:80 open\n" "10.0.1.210:80 open\n" "10.0.1.219:135 open\n" "10.0.1.115:80 open\n" "10.0.1.212:8000 open\n" "10.0.1.191:21 open\n" "10.0.1.115:445 open\n" "10.0.1.102:22 open\n" "10.0.1.52:3306 open\n" "10.0.1.217:443 open\n" "10.0.1.190:135 open\n" "10.0.1.192:135 open\n" "10.0.1.191:445 open\n" "10.0.1.111:443 open\n" "10.0.1.210:443 open\n" "10.0.1.105:80 open\n" "10.0.1.198:22 open\n" "10.0.1.218:443 open\n" "10.0.1.106:80 open\n" "10.0.1.115:81 open\n" "10.0.1.220:1433 open\n" "10.0.1.190:445 open\n" "10.0.1.105:22 open\n" "10.0.1.216:443 open\n" "10.0.1.106:445 open\n" "10.0.1.191:135 open\n" "10.0.1.197:80 open\n" "10.0.1.197:443 open\n" "10.0.1.241:8080 open\n" "10.0.1.216:80 open\n" "10.0.1.210:8000 open\n" "10.0.1.215:80 open\n" "10.0.1.212:443 open\n" "10.0.1.219:443 open\n" "10.0.1.242:80 open\n" "10.0.1.111:80 open\n" "10.0.1.197:82 open\n" "10.0.1.115:8080 open\n" "10.0.1.105:443 open\n" "10.0.1.221:443 open\n" "10.0.1.219:80 open\n" "10.0.1.86:21 open\n" "10.0.1.219:445 open\n" "10.0.1.192:445 open\n" "10.0.1.192:21 open\n" "10.0.1.191:80 open\n" "10.0.1.242:445 open\n" "10.0.1.215:8000 open\n" "10.0.1.215:443 open\n" "10.0.1.101:135 open\n" "10.0.1.115:135 open\n" "10.0.1.198:443 open\n" "10.0.1.86:135 open\n" "10.0.1.115:82 open\n" "10.0.1.115:8888 open\n" "10.0.1.192:82 open\n" "10.0.1.216:8000 open\n" "10.0.1.211:443 open\n" "10.0.1.115:8088 open\n" "10.0.1.191:8090 open\n" "10.0.1.115:10000 open\n" "10.0.1.111:9000 open\n" "10.0.1.219:8099 open\n" "10.0.1.211:9087 open\n" "10.0.1.217:9087 open\n" "10.0.1.218:9087 open\n" "10.0.1.211:2020 open\n" "10.0.1.218:2020 open\n" "10.0.1.217:2020 open\n" "10.0.1.115:20000 open\n" "10.0.1.241:8009 open\n" "10.0.1.211:9084 open\n" "10.0.1.217:9084 open\n" "10.0.1.218:9084 open\n" "10.0.1.101:3000 open\n" "10.0.1.192:83 open\n" "10.0.1.192:90 open\n" "10.0.1.211:9443 open\n" "10.0.1.217:9443 open\n" "10.0.1.218:9443 open\n" "10.0.1.115:7088 open\n" "10.0.1.115:8082 open\n" "10.0.1.115:8300 open\n" "10.0.1.210:8300 open\n" "10.0.1.212:8300 open\n" "10.0.1.216:8300 open\n" "10.0.1.215:8300 open\n" "10.0.1.115:8081 open\n" "10.0.1.192:84 open\n" "10.0.1.211:88 open\n" "10.0.1.217:88 open\n" "10.0.1.218:88 open\n" "10.0.1.211:8084 open\n" "10.0.1.217:8084 open\n" "10.0.1.218:8084 open\n" "10.0.1.210:9080 open\n" "10.0.1.212:9080 open\n" "10.0.1.216:9080 open\n" "10.0.1.215:9080 open\n\n" "[*] 10.0.1.115 (Windows Server 2008 R2 Standard 7601 Service Pack 1)\n" "[*] WebTitle:http://10.0.1.218:9443 400 None\n" "[*] WebTitle:http://10.0.1.191:8090 200 None\n" "[*] WebTitle:http://10.0.1.192:83 200 None\n" "[*] WebTitle:http://10.0.1.217:9084 404 Error 404 Not Found\n" "[*] WebTitle:http://10.0.1.219 200 None\n" "[*] WebTitle:http://10.0.1.115:7088 404 None\n" "[*] WebTitle:http://10.0.1.115:8082 404 None\n" "[*] WebTitle:http://10.0.1.218:9084 404 Error 404 Not Found\n" "[*] 10.0.1.242 (Windows Server 2008 R2 Enterprise 7601 Service Pack 1)\n" "[*] WebTitle:http://10.0.1.211:9443 400 None\n" "[*] WebTitle:http://10.0.1.220 404 None\n" "[*] WebTitle:http://10.0.1.211:9084 404 Error 404 Not Found\n" "[*] WebTitle:http://10.0.1.115:8080 404 None\n" "[*] WebTitle:http://10.0.1.52 200 None\n" "[*] WebTitle:http://10.0.1.115:8088 400 None\n" "[*] WebTitle:https://10.0.1.198 200 None\n" "[*] WebTitle:http://10.0.1.217:9443 400 None\n" "[+] ftp://10.0.1.191:21:anonymous \n" " [->]10594_20110501035吴玮_2003.DOC\n" " [->]aspnet_client\n" " [->]cnki\n" " [->]FILES\n" " [->]weipu\n" " [->]超星\n" "[*] WebTitle:http://10.0.1.115:8081 200 title\n" "[*] WebTitle:http://10.0.1.115 200 title\n" "[*] WebTitle:http://10.0.1.115:8888 405 None\n" "[*] WebTitle:https://10.0.1.101 404 None\n" "[*] WebTitle:https://10.0.1.115 403 None\n" "[*] WebTitle:https://10.0.1.212 200 None\n" "[*] WebTitle:http://10.0.1.105 200 None\n" "[*] WebTitle:https://10.0.1.211 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:https://10.0.1.215 200 None\n" "[*] WebTitle:https://10.0.1.219 200 None\n" "[*] WebTitle:http://10.0.1.197 200 Drcomɏ͸µǂ¼´° \n" "[*] WebTitle:https://10.0.1.216 200 None\n" "[*] WebTitle:http://10.0.1.101:8000 200 用户主页 - 广西科技大学 - 全球最大的虚拟现实三维互动在线教育云平台\n" "[*] WebTitle:http://10.0.1.190 200 广西科技大学学位论文管理系统\n" "[*] WebTitle:https://10.0.1.217 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:http://10.0.1.212 200 None\n" "[*] WebTitle:http://10.0.1.210 200 None\n" "[*] WebTitle:http://10.0.1.211 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:https://10.0.1.210 200 None\n" "[*] WebTitle:http://10.0.1.217 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:http://10.0.1.192:84 200 None\n" "[*] WebTitle:http://10.0.1.218 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:https://10.0.1.218 200 \" + ID_VC_Welcome + \"\n" "[*] WebTitle:http://10.0.1.215 200 None\n" "[*] WebTitle:http://10.0.1.216 200 None\n" "[*] WebTitle:http://10.0.1.191 200 None\n" "[*] WebTitle:http://10.0.1.111:9000 200 平台登录\n" "[*] WebTitle:http://10.0.1.115:82 311 None\n" "[*] WebTitle:http://10.0.1.192:90 200 None\n" "NetInfo:\n" "[*]10.0.1.241\n" " [->]GYZCGL-SERVER1\n" " [->]10.0.1.241\n" " [->]171.168.2.7\n" " [->]172.168.1.5\n" " [->]2002:aba8:207::aba8:207\n" " [->]2002:aca8:105::aca8:105\n" "[+] InfoScan:http://10.0.1.52 Shiro \n" "[*] WebTitle:https://10.0.1.197 200 Drcomɏ͸µǂ¼´° \n" "[*] WebTitle:http://10.0.1.241:8080 404 None\n" "[*] WebTitle:http://10.0.1.242 200 None\n" "[*] WebTitle:http://10.0.1.241 403 403 - ½ûֹ·Îʺ ·Îʱ»¾ܾø¡£\n" "[*] WebTitle:http://10.0.1.219:8099 200 None\n" "[*] WebTitle:http://10.0.1.101 200 Home\n" "[*] WebTitle:https://10.0.1.218:9443 200 None\n" "[*] WebTitle:http://10.0.1.86 403 403 - ½ûֹ·Îʺ ·Îʱ»¾ܾø¡£\n" "[*] WebTitle:https://10.0.1.217:9443 200 None\n" "[*] WebTitle:https://10.0.1.105 200 None\n" "[*] WebTitle:https://10.0.1.211:9443 200 None\n" "[*] 10.0.1.241 (Windows Server 2008 R2 Enterprise 7601 Service Pack 1)\n" "[*] WebTitle:http://10.0.1.192:82 200 None\n" "[*] WebTitle:http://10.0.1.106 200 柳州市节能科技产业孵化园\n" "[*] WebTitle:https://10.0.1.221 200 None\n" "[*] WebTitle:http://10.0.1.115:81 400 None\n" "[+] https://10.0.1.211 poc-yaml-vmware-vcenter-unauthorized-rce-cve-2021-21972\n" "[+] https://10.0.1.218 poc-yaml-vmware-vcenter-unauthorized-rce-cve-2021-21972\n" "[+] https://10.0.1.217 poc-yaml-vmware-vcenter-unauthorized-rce-cve-2021-21972\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