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

/
/
g

Test String

Code Generator

Generated Code

$re = '/\??( ((action_)((object)|(type)|(ref))(_map))| (spm)|(scm(\-|_)(.*?))|(aff_)(.*?)|(algo_)(.*?)|(btsid)|(ws_)(.*?)| (pd_rd_)(.*?)|(_encoding)|(psc)|(tag)|(ref_)|(pf)|(pf_rd_)(.*?)| (callback)| (cvid)|(form)|(sk)|(sp)|(qs)|(pq)| (mkt_tok)| (trk(Campaign)?)| (ga_)(.*?)|(gclid)|(gclsrc)| (hmb_)((campaign)|(medium)|(source))| ((sp)((Report)|(Job)|(User)|(Mailing))(ID))| (itm_)(.*?)| (s_cid)| (elq((Track)?Id)?)|(elqTrack)|(assetType)|(assetId)|(recipientId)|(сampaignId)|(siteId)| (mc_(c|e)id)| (pk_)(.*?)| (sc_)(.*?)| (utm_)(.*?)|(nr_email_referer)| (vero_(.*?))| (nr_)(.*?)| (yclid)|(_openstat)|(lr)|(redircnt)| (mbid)|(cmpid)|(cid)|(c_id)|(campaign_id)|(Campaign)| (fb_)(.*?)|(fbclid)|(f?ref)|(refsrc)|(hrc)| (gw?s_)(.*?)|(ved)|(s?ei)| (_hsenc)|(_hsmi)|(__hssc)|(__hstc)|(hsCtaTracking)| (source)|(position)| (tt_)(.*?)| (wt_)(.*?)| (hc)|(fb)|(yc)|(fan)|(asb)|(asb2)|(mindbox)|(from)|(sh)|(keywords?)|(feature)|(mlid)|(stid)|(topnews_)(.*?)|(persistent_)(.*?)|(msid)|(rubric)|(lang)|(t?t=)(.*?)|(d)|(s)|(psf)|(sourceType)|(short)|(pdp_ext_f)|(utparam)|(pvid))(=(.*?)|(?=(&|$|\r|\n|")))(?=(&|$|\r|"|\n))/'; $str = 'https://yandex.ru/news/story/Prezident_Tokaev_prinyal_otstavku_pravitelstva_Kazakhstana--243e04d37f1419500c9ece814c1d9e30?lang=ru&rubric=index&fan=1&stid=byyvfKwXr5iSKBBZZOVN&t=1641352850&tt=true&persistent_id=176465644& https://www.aliexpress.com/item/4000317035065.html?pdp_ext_f=%7B%22ship_from%22%3A%22CN%22%2C%22sku_id%22%3A%2212000018551624449%22%7D&sourceType=fd&scm_id=1007.28480.226530.0&scm-url=1007.28480.226530.0&pvid=4ae1761c-d2f8-43f3-a91d-68763fb50e0b&utparam=%257B%2522process_id%2522%253A%2522110%2522%252C%2522x_object_type%2522%253A%2522product%2522%252C%2522pvid%2522%253A%25224ae1761c-d2f8-43f3-a91d-68763fb50e0b%2522%252C%2522belongs%2522%253A%255B%257B%2522id%2522%253A%25224001%2522%252C%2522type%2522%253A%2522dataset%2522%257D%255D%252C%2522scm%2522%253A%25221007.28480.226530.0%2522%252C%2522tpp_buckets%2522%253A%252221669%25230%2523186385%25230_21669%25234190%252319163%2523569_15324%25230%2523132599%25230%2522%252C%2522x_object_id%2522%253A%25224000317035065%2522%257D'; 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