Regular Expressions 101

Save & Share

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

/
/
i

Test String

Substitution

Processing...

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"^\S*\S+\s+[a-fA-F0-9.]+\s+DATA\s+Auth\s+(\S+)\s*$" test_str = ("Gi1/0/25 0001.2e68.c47b mab DATA Auth 000000000000469AB6F2D0A2\n" "Gi1/0/39 0c8d.dbc5.7da8 mab DATA Auth 000000000000466BB2BF922F\n" "Gi1/0/8 7c4a.8201.a189 mab DATA Auth 00000000000046CFBA8ACF3E\n" "Gi1/0/9 7c4a.8201.a506 mab DATA Auth 00000000000046CEBA8A9660\n" "Gi1/0/15 0001.2e68.cc47 mab DATA Auth 00000000000046ACB6F35DE1\n" "Gi1/0/18 0001.2e68.c66c mab DATA Auth 00000000000046AFB6F37505\n" "Gi1/0/14 0001.2e68.c376 mab DATA Auth 00000000000046A9B6F3261B\n" "Gi1/0/6 0012.e506.0307 mab DATA Auth 00000000000045CCAA38FB62\n" "Gi1/0/2 0001.2e69.b955 mab DATA Auth 00000000000046B3B7ED23A6\n" "Gi1/0/31 0001.2e68.c37f mab DATA Auth 00000000000046A5B6F303BA\n" "Gi1/0/26 0001.2e68.c6a5 mab DATA Auth 000000000000469FB6F2E6BA\n" "Gi1/0/1 0001.2e69.b98c mab DATA Auth 0000000000004675B2FF684C\n" "Gi1/0/4 0001.2e69.b9ef mab DATA Auth 00000000000046B1B7ECAB2B\n" "Gi1/0/5 0025.3601.7334 mab DATA Auth 00000000000046C5B9DD1F0F\n" "Gi1/0/20 0001.2e68.c36f mab DATA Auth 00000000000046ABB6F3473A\n" "Gi1/0/29 0001.2e68.c492 mab DATA Auth 000000000000469EB6F2D9E4\n" "Gi1/0/36 0c8d.dbc5.5327 mab DATA Auth 0000000000004668B2BF89E6\n" "Gi1/0/30 0001.2e5f.4561 mab DATA Auth 00000000000046C7BA45DDEB\n" "Gi1/0/22 0001.2e68.c654 mab DATA Auth 00000000000046ADB6F35DE4\n" "Gi1/0/27 0001.2e68.c6b4 mab DATA Auth 00000000000046A0B6F2EB5B\n" "Gi1/0/13 0001.2e68.c35c mab DATA Auth 00000000000046A4B6F2FC37\n" "Gi1/0/3 0025.36fe.c560 mab DATA Auth 00000000000043267E44A554\n" "Gi1/0/37 0c8d.dbc4.f3a1 mab DATA Auth 0000000000004669B2BF8AFD\n" "Gi1/0/21 0001.2e68.c4a6 mab DATA Auth 00000000000046AEB6F363FF\n" "Gi1/0/19 0001.2e68.c6a0 mab DATA Auth 000000000000469CB6F2D68F\n" "Gi1/0/16 0001.2e68.c66d mab DATA Auth 00000000000046A8B6F3213E\n" "Gi1/0/42 0c8d.dbc5.5316 mab DATA Auth 000000000000466AB2BF9015\n" "Gi1/0/17 0001.2e68.c6a8 mab DATA Auth 00000000000046AAB6F32DC0\n" "Gi1/0/40 0c8d.dbc5.7a5b mab DATA Auth 000000000000466CB2BF99C0\n" "Gi1/0/35 0c8d.dbc5.7003 mab DATA Auth 000000000000466DB2BF9B16\n" "Gi1/0/23 0001.2e68.c489 mab DATA Auth 0000000000004697B6F2BABC\n" "Gi1/0/10 7c4a.8201.a531 mab DATA Auth 00000000000046B6B8AF5E00\n" "Gi1/0/41 0c8d.dbc5.7bb8 mab DATA Auth 000000000000466EB2BFB123\n" "Gi1/0/38 0c8d.dbc5.775d mab DATA Auth 0000000000004667B2BF855D\n" "Gi1/0/11 001b.eb45.7fd3 mab DATA Auth 00000000000046B9B936EB15\n" "Gi1/0/28 0001.2e68.cd25 mab DATA Auth 000000000000468EB6A8476B\n") subst = "Gi1/0/25" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 1, re.IGNORECASE) if result: print (result) # 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