Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Code Generator

Generated Code

$re = '~https://www\.amazon\.com(?:/[^/]+)?/[dg]p/([a-zA-Z0-9]{10})~m'; $str = 'https://www.amazon.com/Mercer-Collective-Reversible-Faux-Leather-Small/dp/B0FYH2DLLR/ref=sr_1_1?ie=UTF8&sr=1-1&qid=1769005210&srs=205709307011&content-id=amzn1.sym.f0071731-e15a-4e45-8136-9db6ef13dd66&pd_rd_w=38d4z&dib=eyJ2IjoiMSJ9.9cZBdzbUw1keg_XBUAeM15nKBleTLr7XtAGrD3tTnPQR_z7zrzRRwc7Itf1hZU-gAz81I3HguoxJAtTgM-gwq11vb1fkGuuEfU8epVM5sw5L7rX8JwLHUn8GuAEZQuX42c1u_b7LRNjoMGM3XsV0ksSHLEoHMtYFvv-GP1VsJ4zAIYHXlWkD0gEqS3E06fHv7tzNrBXw4RwMFm8Si2aD2-NhDdxcCk-zCkyRON6QIhw8RqimztymDy8U4r9EWHHLO7i2_Wdm5mh0UemBhfHInkUtrBIrB8OdHX8ankxS7_4.rP_vwMtZee1y0ghS1SG4-I4ZcA0MGQu0tK-ooldvBNU&rnid=20722812011&dib_tag=se&pd_rd_r=b1d1a80e-e547-4774-b819-cfde1f993011&ASIN=B0FYH2DLLR&_encoding=UTF8&pd_rd_wg=MR2dC&ref_=lx_bd&th=1'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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