Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"(?m)\$([^{("\\'\/])([a-zA-Z0-9_]*)([^}\/ \t'"\n.\]:]*)"#).unwrap(); let string = "#!/usr/bin/env bash # version 0.1.0 function generate_secret() { ( umask 0077 ; dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 > \"$1\" ) } if [[ -n $SRS_DOMAINNAME ]] then NEW_DOMAIN_NAME=\"$SRS_DOMAINNAME\" elif [[ -n $OVERRIDE_HOSTNAME ]] then NEW_DOMAIN_NAME=\"${OVERRIDE_HOSTNAME#*.}\" elif [[ -n $DOMAINNAME ]] then NEW_DOMAIN_NAME=\"$DOMAINNAME\" else NEW_DOMAIN_NAME=$(hostname -d) fi sed -i -e \"s/localdomain/${NEW_DOMAIN_NAME}/g\" /etc/default/postsrsd POSTSRSD_SECRET_FILE='/etc/postsrsd.secret' POSTSRSD_STATE_DIR='/var/mail-state/etc-postsrsd' POSTSRSD_STATE_SECRET_FILE=\"${POSTSRSD_STATE_DIR}/postsrsd.secret\" if [[ -n $SRS_SECRET ]] then ( umask 0077 ; echo \"$SRS_SECRET\" | tr ',' '\\n' > \"$POSTSRSD_SECRET_FILE\" ) else if [[ $ONE_DIR -eq 1 ]] then if [[ ! -f $POSTSRSD_STATE_SECRET_FILE ]] then install -d -m 0775 \"$POSTSRSD_STATE_DIR\" generate_secret \"$POSTSRSD_STATE_SECRET_FILE\" fi install -m 0400 \"$POSTSRSD_STATE_SECRET_FILE\" \"$POSTSRSD_SECRET_FILE\" elif [[ ! -f $POSTSRSD_SECRET_FILE ]] then generate_secret \"$POSTSRSD_SECRET_FILE\" fi fi if [[ -n $SRS_EXCLUDE_DOMAINS ]] then sed -i -e \"s/^#\\?SRS_EXCLUDE_DOMAINS=.*$/SRS_EXCLUDE_DOMAINS=$SRS_EXCLUDE_DOMAINS/g\" /etc/default/postsrsd fi /etc/init.d/postsrsd start "; let substitution = "${$1$2$3}"; // result will be a String with the substituted value let result = regex.replace_all(string, substitution); println!("{}", result); }

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 Rust, please visit: https://docs.rs/regex/latest/regex/