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

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