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

/
/

Test String

Code Generator

Generated Code

$re = '/<li><a href="" target="_blank">[\n](.*?)[\n](https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})[\n]<\/a><\/li>/'; $str = '<li><a href="" target="_blank"> Best Buy – Mount Laurel, NJ – Robbery https://patch.com/new-jersey/cinnaminson/7-3k-electronics-stolen-burlington-co-store-suspect-sought </a></li> <li><a href="" target="_blank"> C-Store- Yuma, AZ – Armed Robbery https://arizonadailyindependent.com/2023/02/14/yuma-county-sheriffs-deputies-make-robbery-arrest/ </a></li> <li><a href="" target="_blank"> C-Store – Jasper, TX – Armed Robbery https://www.kjas.com/news/local_news/article_c5a5133a-ace7-11ed-9a1b-630ed466fb7f.html </a></li> <li><a href="" target="_blank"> C-Store – Colorado Springs, CO – Armed Robbery https://gazette.com/news/crime/shots-fired-during-attempted-armed-robbery-in-east-colorado-springs/article_96f7de40-ac70-11ed-ad96-2b1db289229e.html </a></li> <li><a href="" target="_blank"> C-Store – Houston, TX – Armed Robbery https://mobile.twitter.com/KHOU/status/1625379198322806785 </a></li> <li><a href="" target="_blank"> C-Store – Kanawha County, WV – Armed Robbery https://www.wsaz.com/2023/02/15/deputies-investigating-armed-robbery-gas-station/ </a></li> <li><a href="" target="_blank"> Department – Cleveland, OH – Robbery https://www.cleveland.com/community/2023/02/man-already-banned-from-returning-to-beachwood-place-until-2028-arrested-for-stealing-mall-merchandise-beachwood-police-blotter.html </a></li> <li><a href="" target="_blank"> Dollar – Akron, OH – Armed Robbery https://www.cleveland.com/crime/2023/02/akron-police-investigate-armed-robbery-of-dollar-general-clerk.html </a></li> <li><a href="" target="_blank"> Grocery – Showell, MD – Armed Robbery https://www.wrde.com/news/troopers-ask-for-help-in-identifying-man-suspected-in-showell-armed-robbery/article_c2e57e92-ac78-11ed-a628-7fba37176075.html </a></li> <li><a href="" target="_blank"> Guns – Lansing, IL – Burglary https://www.fox32chicago.com/news/police-seek-smash-and-grab-crew-who-burglarized-canada-goose-lansing-gun-store </a></li> <li><a href="" target="_blank"> Hardware – Tulsa, OK – Robbery https://www.fox23.com/news/video-three-men-arrested-stealing-thousands-dollars-flooring-tile/3708187a-4784-4ea5-b9c7-04971b6315dc/ </a></li> <li><a href="" target="_blank"> Marijuana – Los Angeles, CA – Burglary https://www.cbsnews.com/losangeles/video/fairfax-dispensary-burglary-foiled-by-lapd-response/ </a></li> <li><a href="" target="_blank"> Marijuana – Lynnwood, WA – Burglary https://ustimespost.com/thieves-ram-truck-into-lynnwood-pot-shop-in-attempted-atm-robbery/ </a></li> <li><a href="" target="_blank"> Marijuana – New York, NY – Robbery https://www.audacy.com/1010wins/news/local/suspect-spray-manhattan-smoke-shop-worker-steal-usd300-in-weed </a></li> <li><a href="" target="_blank"> Marijuana - Los Angeles, CA – Burglary https://www.cbsnews.com/losangeles/video/fairfax-dispensary-burglary-foiled-by-lapd-response/ </a></li> <li><a href="" target="_blank"> Marijuana – Moore, OK – Burglary https://kfor.com/news/local/two-in-custody-after-burglary-of-oklahoma-dispensary/ </a></li> <li><a href="" target="_blank"> Pawn – Lewisville, TX – Armed Robbery / Owner killed https://www.crosstimbersgazette.com/2023/02/14/lewisville-police-seeking-3-suspects-in-capital-murder-of-pawn-shop-owner/ </a></li> <li><a href="" target="_blank"> Pharmacy – Chautauqua County, NY – Robbery https://www.observertoday.com/news/top-stories/2023/02/robbery-suspect-identified-by-silver-creek-cameras/ </a></li> <li><a href="" target="_blank"> Restaurant – Oakland, CA – Robbery https://deleciousfood.com/oakland-restaurant-manager-details-robbery-similar-to-the-one-that-killed-angel-cakes-owner-jen-angel-2/ </a></li> <li><a href="" target="_blank"> Tobacco – New York, NY – Armed Robbery https://citizen.com/-NOIfeXowunwknAhxrL3 </a></li> <li><a href="" target="_blank"> Vape – Lincoln, NE – Burglary https://www.1011now.com/2023/02/14/police-investigating-burglary-northeast-lincoln-vape-shop/ </a></li> '; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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