Regular Expressions 101

Save & Share

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

re = /https:(.*?)\/track\/(.*?)\?(.*)/m str = 'https://open.spotify.com/track/7cy1bEJV6FCtDaYpsk8aG6?si=4NrCtBYRRt6QIEggvr5-UQ https://open.spotify.com/track/2mKS9ECgxNSRQgmQO7CY8x?si=70ua2XGPTvy5tg3tAfSIHQ https://open.spotify.com/track/1rqqCSm0Qe4I9rUvWncaom?si=j8IHrLXASjmgSOc77seefQ https://open.spotify.com/track/7MRY4VpCuZvBmFda6ZCk2G?si=BIlDAq22RkSb559U3Ymdgw https://open.spotify.com/track/1yG1OpMiV8WtDeOYEBvNW8?si=VSOSzYHCQGW7-DZoDTq15A https://open.spotify.com/track/0zYkf4pCiGAhEp5Z3iUkml?si=DQ0o-GGRQfmqABxDcqeywQ https://open.spotify.com/track/4HCcvFdHfwR2u3WPPPVRv6?si=N_l1p_fMTXSYdEA2V4uKKg https://open.spotify.com/track/6A3ff44rkAsNUPq5ZpG0Lw?si=X6E_z8ClSm-gqOh_PNJ8aA https://open.spotify.com/track/1owidcBLuyqbtlJRWyRubJ?si=AfuGmcQ4RL6znQrBnHNsUQ https://open.spotify.com/track/72OeMxh65OcA6riQ7fRH6c?si=jXksouMoTTy9gHiusgAN3Q https://open.spotify.com/track/1PqZRvgKb2OepsA7aeb64y?si=n7RCpDM_TOeAsSSgJqecCQ https://open.spotify.com/track/4K8pmNLIAhetFRpEBGV0dJ?si=O_Vwez-xQ-ufDqeSjJmYjw https://open.spotify.com/track/3DVNUiBeYKbp7JvvcrfqZB?si=vRTYM_lXRP--LwoFg44M8Q https://open.spotify.com/track/4w2iAP3X4FkpPb5kjRdIDx?si=w0PH7da9RgeWspRVYrFeFw https://open.spotify.com/track/0Y2QWrhPh6ATyaWYT0QLIR?si=hwnF_-1aTcioBOSJLHNE1w https://open.spotify.com/track/4pkZNPC6yeMnQABwkTmsR6?si=JC6rPKnBQRCGF6NP9I6QKg https://open.spotify.com/track/5rR1C059TESZuNiiYEzZBa?si=-ncveFyxS3KDa7Yf54opZg https://open.spotify.com/track/6aFc0W6xVS9kN9E9NGekAl?si=9Jiu-bANSuaPPjJOE_b5GQ https://open.spotify.com/track/6ZF6PsmadIgyuxp0wqD9qO?si=HardRQQzSXGMxiscNsuuIQ https://open.spotify.com/track/7HhawuOJ17618C4VJfJn2K?si=Ve0FWw02SDuhA3FO9ZRfVA https://open.spotify.com/track/2ZFAzZ5uluMR8TeO6YEy52?si=QYw76ZYDTAqmigwp-4K0_w https://open.spotify.com/track/7IO8jHHbV9P4VtcfeGvEZy?si=xp4fWYXVQP-NBhjF6M6LkQ https://open.spotify.com/track/0CLYfCWlqR1zB6Wqi6VTwy?si=_yiWBH82SUmNfKrcoUFSXw https://open.spotify.com/track/4PAT0WuPzHOn94bP0BYZUz?si=oPcZRxB0TYGbjzvz54ZkPw https://open.spotify.com/track/5XKDliIGPTUnNRwRZsd0oN?si=okAtielaT2ChEL2vK3DV8Q https://open.spotify.com/track/5fpj84RsT9cOTfWUCxBTXu?si=5He0nt3oQzSipKrtwaKJ-A' subst = 'spotify:track:$2' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html