Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
g

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"\* \[([^\!][^\]]*)\]\(https?\:\/\/github\.com\/([^\/]+\/[^\/\)]+)\/?[^\)]*\)" test_str = ("# Awesome SSH [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)\n\n" "> A curated list of *SSH* [apps](#apps), [libraries](#libraries) and [resources](#resources).\n\n" "<h2 align=\"center\"><img src=\"https://raw.githubusercontent.com/moul/awesome-ssh/master/logo.jpg\" width=\"400\" /></h2>\n\n" "Inspired by the [awesome](https://github.com/sindresorhus/awesome) list thing.\n\n" "Please read the [contribution guidelines](CONTRIBUTING.md) if you want to contribute.\n\n" "**Check out my [blog](http://manfredtouron.tumblr.com) 🦄 or say *hi* on [Twitter](https://twitter.com/moul).**\n\n" "## Table of Contents\n\n" "- [Apps](#apps)\n" " - [`.ssh/config`](#sshconfig)\n" " - [Tools using the *SSH* protocol](#tools-using-the-ssh-protocol)\n" " - [Servers](#servers)\n" " - [Network](#network)\n" " - [Multiplexers](#multiplexers)\n" " - [SSH Keys / Authentication](#ssh-keys--authentication)\n" " - [SSH agent](#ssh-agent)\n" " - [Tools](#tools)\n" " - [Automation](#automation)\n" " - [Web](#web)\n" " - [Testing / Honeypots](#testing--honeypots)\n" " - [Alternatives to SSH](#alternatives-to-ssh)\n" "- [Libraries](#libraries)\n" "- [Resources](#resources)\n" " - [Tutorials](#tutorials)\n" " - [Security](#security)\n" " - [Documentation](#documentation)\n" " - [Community](#community)\n\n" "## Apps\n\n" "### `.ssh/config`\n\n" "* [`assh` a.k.a `advanced-ssh-config`](https://github.com/moul/advanced-ssh-config) - Transparent wrapper (ProxyCommand) that adds regex, aliases, gateways, includes, dynamic hostnames to *SSH* and `ssh-config`.\n" "* [storm](https://github.com/emre/storm) - Manage your *SSH* like a boss.\n" "* [ansible-ssh-config](https://github.com/gaqzi/ansible-ssh-config) - Letting *Ansible* manage `ssh_config`.\n" "* [ec2ssh](https://github.com/mirakui/ec2ssh) - A `ssh_config` manager for *AWS EC2*.\n" "* [ssh-config](https://github.com/dbrady/ssh-config) - A tool to help manage your `.ssh/config` file.\n\n" "### Tools using the *SSH* protocol\n\n" "* [scp](http://linux.die.net/man/1/scp) - Secure remote file copy utility over *SSH*.\n" "* [rsync](https://rsync.samba.org) - Fast incremental transfer utility that supports *SSH*.\n" "* [sftp](https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol) - File transfer protocol over *SSH*.\n" "* [curl](http://curl.haxx.se) - Command line tool and library to transfer data (support `sftp`).\n\n" "### Servers\n\n" "* [ssh2docker](https://github.com/moul/ssh2docker) - *SSH* server to Docker containers.\n" "* [whosthere](https://github.com/FiloSottile/whosthere) - A *SSH* server that knows who you are. `$ ssh whoami.filippo.io`.\n" "* [sshfront](https://github.com/gliderlabs/sshfront) - Programmable *SSH* frontend.\n" "* [ssh-chat](https://github.com/shazow/ssh-chat) - Chat over *SSH*.\n" "* [sshcommand](https://github.com/dokku/sshcommand) - Turn *SSH* into a thin client specifically for your app.\n" "* [sshmuxd](https://github.com/joushou/sshmuxd) - `sshmux` frontend.\n" "* [x84](https://github.com/jquast/x84) - A *python* `telnet`/`ssh` server for modern *UTF-8* and classic *cp437* network virtual terminals. In spirit of classic software such as *ami/x*, *teleguard*, *renegade*, *iniquity*.\n" "* [teleport](https://github.com/gravitational/teleport) - Modern *SSH* server for clusters and teams.\n\n" "### Network\n\n" "* [Mosh](https://mosh.mit.edu) - The mobile shell.\n" "* [sshfs](https://github.com/libfuse/sshfs) - Filesystem client based on the *SSH* File Transfer Protocol.\n" "* [ngrok](https://github.com/inconshreveable/ngrok) - Introspected tunnels to localhost.\n" "* [localtunnel](https://github.com/progrium/localtunnel) - Expose localhost servers to the Internet.\n" "* [sshuttle](https://github.com/apenwarr/sshuttle) - Transparent proxy server that works as a poor man's *VPN*. Forwards over `ssh`. Doesn't require admin. Works with *Linux* and *MacOS*. Supports *DNS tunneling*.\n" "* [sshttp](https://github.com/stealth/sshttp) - *SSH*/*HTTP(S)* multiplexer. Run a webserver and a `sshd` on the same port w/o changes.\n" "* [switcher](https://github.com/jamescun/switcher) - Run *SSH* and *HTTP(S)* on the same port.\n" "* [sslh](https://github.com/yrutschle/sslh) - Applicative Protocol Multiplexer (i.e: *SSH* + *HTTPS*).\n" "* [tund](https://github.com/aphyr/tund) - *SSH* reverse tunnel daemon.\n" "* [autossh](http://www.harding.motd.ca/autossh/) - Automatically respawn *SSH* session after network interruption.\n" "* [wssh](https://github.com/aluzzardi/wssh) - *SSH* to WebSockets Bridge.\n" "* [docker-volume-sshfs](https://github.com/vieux/docker-volume-sshfs) - `sshfs` docker volume plugin.\n\n" "### Multiplexers\n\n" "* [tmux](https://tmux.github.io) - Terminal multiplexer.\n" "* [clusterssh](https://github.com/duncs/clusterssh) - Cluster admin via *SSH*.\n" "* [tmux-cssh](https://github.com/dennishafemann/tmux-cssh) - `tmux` with a *ClusterSSH*-like behavior.\n" "* [tm](https://github.com/Ganneff/tm) - `tmux` manager / helper.\n" "* [i2cssh](https://github.com/wouterdebie/i2cssh) - `csshX` like *SSH* tool for *iTerm2*.\n" "* [ClusterSSH](http://sourceforge.net/projects/clusterssh/) - Controls a number of `xterm` windows via a single graphical console.\n\n" "### *SSH* keys / Authentication\n\n" "* [authy-ssh](https://github.com/authy/authy-ssh) - Easy *two-factor* authentication for *SSH* servers.\n" "* [github-auth](https://github.com/chrishunt/github-auth) - *SSH* key management for GitHub users.\n" "* [cipherhub](https://github.com/substack/cipherhub) - Encrypt messages based on *SSH* public keys with easy import from GitHub.\n" "* [Slack notifications](http://www.ryanbrink.com/slack-ssh-session-notifications/) - Guide to setup Slack notifications (can be modified for other services).\n" "* [totp-ssh-fluxer](https://github.com/benjojo/totp-ssh-fluxer) - A way to make sure your `sshd` port changes every 30 seconds.\n\n" "### *SSH* agent\n\n" "* [ssh-ident](https://github.com/ccontavalli/ssh-ident) - Different agents and different keys for different projects, with `ssh`.\n" "* [oh-my-zsh/plugins/ssh-agent](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/ssh-agent) - `ssh-agent` plugin for `zsh`.\n\n" "### Tools\n\n" "* [sshrc](https://github.com/Russell91/sshrc) - Bring your `.bashrc`, `.vimrc`, etc. with you when you `ssh`.\n\n" "### Automation\n\n" "* [Ansible](https://github.com/ansible/ansible) - App deployment, configuration management and orchestration over *SSH*.\n" "* [rtop](https://github.com/rapidloop/rtop) - Interactive, remote system monitoring tool based on *SSH*.\n" "* [DSH - Dancer's shell / distributed shell](https://www.netfort.gr.jp/~dancer/software/dsh.html.en) - Wrapper for executing multiple remote shell commands from one command line.\n" "* [parallel-ssh](https://code.google.com/p/parallel-ssh/) - Provides parallel versions of OpenSSH and related tools.\n" "* [SSH Power Tool](https://code.google.com/p/sshpt/) - Execute commands and upload files to many servers simultaneously without using pre-shared keys.\n\n" "### Web\n\n" "* [Secure Shell chrome extension](https://chrome.google.com/webstore/detail/secure-shell/pnhechapfaindjhompbnflcldabbghjo?hl=en)\n" "* [GateOne](https://github.com/liftoff/GateOne) - HTML5-powered terminal emulator and *SSH* client.\n" "* [KeyBox](https://github.com/skavanagh/KeyBox) - Web-based *SSH* console that centrally manages administrative access to systems.\n" "* [Apache Guacamole](https://guacamole.incubator.apache.org/) - Apache Guacamole is a HTML5 based clientless remote desktop gateway. It supports standard protocols like VNC, RDP, and SSH. \n\n" "### Testing / Honeypots\n\n" "* [ssh-hammer](https://github.com/shazow/ssh-hammer) - *SSH* load testing tool.\n" "* [kippo](https://github.com/desaster/kippo) - *SSH* Honeypot.\n" "* [cowrie](https://github.com/micheloosterhof/cowrie) - *SSH* Honeypot (based on kippo).\n" "* [sshmitm](http://linux.die.net/man/8/sshmitm) - *SSH* monkey-in-the-middle.\n" "* [ssh-audit](https://github.com/arthepsy/ssh-audit) - A tool for *SSH* server auditing.\n" "* [sshesame](https://github.com/jaksi/sshesame) - A fake SSH server that lets everyone in and logs their activity.\n\n\n" "### Alternatives to *SSH*\n\n" "* [GoTTY](https://github.com/yudai/gotty) - Share your terminal as web application.\n" "* [telnet](http://www.telnet.org/htm/faq.htm) - An unencrypted network protocol and an application used to connect to remote computers and issue commands.\n" "* [rsh](https://en.wikipedia.org/wiki/Remote_Shell) - An unencrypted network protocol and application used to connect to remote computers and issue commands.\n\n" "## Libraries\n\n" "* C/C++\n" " * [libssh](https://www.libssh.org) - The *SSH* library.\n" " * [substack/libssh](https://github.com/substack/libssh) - Multiplatform C library implementing the SSHv2 and SSHv1 protocol on client and server side.\n" "* Golang\n" " * [crypto/ssh](https://godoc.org/golang.org/x/crypto/ssh) - Built-in *SSH* client and server library.\n" " * [sftp](https://github.com/pkg/sftp) - *SFTP* support for the go.crypto/ssh package.\n" " * [go-sshkit](https://github.com/shazow/go-sshkit) - Toolkit for building *SSH* servers and clients in Go.\n" " * [Socker](https://github.com/cosiner/socker) - Library for Go to simplify the use of *SSH*.\n" "* Java\n" " * [jsch](http://www.jcraft.com/jsch/) - Pure *java*, *BSD* licensed, *SSH2* client library.\n" "* Javascript/Node.js\n" " * [ssh2](https://github.com/mscdex/ssh2) - *SSH2* client and server modules written in pure *JavaScript* for *node.js*.\n" "* Python\n" " * [paramiko](https://github.com/paramiko/paramiko) - Native *Python* *SSHv2* protocol library.\n" "* Ruby\n" " * [net-ssh](https://github.com/net-ssh/net-ssh) - Pure *Ruby* implementation of an *SSH* (protocol 2) client.\n\n" "## Resources\n\n" "### Tutorials\n\n" "* [How to use *SSH* to Connect to a Remote Server](https://www.digitalocean.com/community/tutorials/how-to-use-ssh-to-connect-to-a-remote-server-in-ubuntu)\n" "* [Best practices](https://blog.0xbadc0de.be/archives/300)\n" "* [Granting Temporary Access to Your Servers (Using Signed *SSH* Keys)](http://linux-audit.com/granting-temporary-access-to-servers-using-signed-ssh-keys/)\n" "* [How to SSH login without a password](https://www.rosehosting.com/blog/ssh-login-without-password-using-ssh-keys/)\n\n" "### Security\n\n" "* [01/14/2016](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-0777) - Integer Overflow `CVE 2016 077[7-8]`.\n" "* [Security/Guidelines/OpenSSH - MozillaWiki](https://wiki.mozilla.org/Security/Guidelines/OpenSSH) - `sshd\\_config` for `6.7+`, `5.3`.\n" "* [Applied-Crypto-Hardening](https://github.com/BetterCrypto/Applied-Crypto-Hardening/tree/master/src/configuration/SSH/OpenSSH) - `sshd\\_config` for `6.X`\n\n" "### Documentation\n\n" "* [man page](http://linux.die.net/man/1/ssh)\n" "* [Specifications (OpenSSH)](http://www.openssh.com/specs.html)\n" "* [Wikipedia article](https://en.wikipedia.org/wiki/Secure_Shell)\n\n" "### Community\n\n" "* [StackOverflow](http://stackoverflow.com/questions/tagged/ssh)\n" "* [ServerFault](http://serverfault.com/questions/tagged/ssh)\n\n" "## License\n\n" "[![CC0](https://i.creativecommons.org/p/zero/1.0/88x31.png)](https://creativecommons.org/publicdomain/zero/1.0/)\n\n" "To the extent possible under law, [Manfred Touron](https://github.com/moul) has waived all copyright and related or neighboring rights to this work.\n") matches = re.finditer(regex, test_str) 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