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

/
/
mgi

Test String

Code Generator

Generated Code

$re = '/([(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b([-a-zA-Z0-9@:%_\+~#?&\/\/=]*)|(http(s)?:\/\/\/?)/mi'; $str = 'Title: Government URLs Author: DigitalGov Search Keywords: Scope: Federal, state, local, tribal, and territorial government websites that aren\\\'t *.gov or *.mil. Quarterly updates are also posted at https://github.com/GSA/govt-urls. URI: http://govt-urls.usa.gov/tematres/vocab/ Powered by: TemaTres 1.63 Something: geekdrop.com Catch 3 Slashes SSL: https:/// Catch 3 Slashes: http:// __________________________________________________________________________ 1-800-vermont.com created: 2013-06-06 19:11:14 Scope note: Travel and Tourism Site for Vermont RTET: VermontVacation.com BT: usagovVT 174.132.145.94/~hope created: 2013-06-06 18:09:02 modified: 2013-11-20 15:27:15 Scope note: Town of Hope Mills, NC BT: usagovNC UF: townofhopemills.com 1800arkansas.com USE: arkansasedc.com 1800runaway.org created: 2014-01-10 19:15:25 Scope note: The National Runaway Safeline serves as the federally designated national communication system for runaway and homeless youth. Services are provided through funding from Family and Youth Services Bureau in the Administration for Children and Families, U.S. Department of Health and Human Services and the generosity of private funders (individual donors, corporate partners, and foundation grants). BT: usagovQUASI 211.getcare.com created: 2014-05-27 14:12:29 Scope note: 2-1-1 VIRGINIA is a service of the Virginia Department of Social Services provided in partnership with the Council of Community Services, the Family Resource and Referral Center, The Planning Council, the United Way of Central Virginia, and the United Way of Greater Richmond and Petersburg. RT: 211virginia.org BT: usagovVA 211virginia.org created: 2014-01-10 19:17:31 Scope note: 2-1-1 VIRGINIA is a service of the Virginia Department of Social Services provided in partnership with the Council of Community Services, the Family Resource and Referral Center, The Planning Council, the United Way of Central Virginia, and the United Way of Greater Richmond and Petersburg. RT: 211.getcare.com BT: usagovVA 360eldorado.com/Government created: 2013-11-19 12:54:52 Scope note: City of El Dorado, KS RT: eldoks.com BT: usagovKS 3riverscfc.org created: 2013-06-06 18:08:14 Scope note: 3 Rivers/Pennsylvania West Combined Federal Campaign BT: usagovOH BT: usagovPA BT: usagovWV 4thjudicialda.com created: 2014-01-10 19:17:31 Scope note: 4th Judicial District Attorney BT: usagovCO 511ny.org created: 2014-01-24 14:33:30 Scope note: 511 NY (New York State Department of Transportation), the free, official one-stop, all-encompassing telephone and Web service offering information on transportation services and conditions throughout New York State. BT: usagovNY 800alabama.com USE: alabama.travel 911digitalarchive.org created: 2013-06-06 18:08:14 Scope note: The September 11 Digital Archive (funded by a major grant from the Alfred P. Sloan Foundation and organized by the American Social History Project at the City University of New York Graduate Center and the Center for History and New Media at George Mason University) BT: usagovQUASI aacounty.org created: 2013-06-06 18:08:14 Scope note: Anne Arundel County, MD BT: usagovMD aapcc.org created: 2014-01-10 19:19:24 Scope note: American Association of Poison Control Centers BT: usagovQUASI aatwp.org created: 2013-06-06 18:08:14 BT: usagovMI aberdeen-md.org created: 2013-06-06 18:08:14 Scope note: City of Aberdeen, MD BT: usagovMD aberdeen.sd.us created: 2013-06'; 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