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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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
No Match

/
/
gmi

Test String

Code Generator

Generated Code

const regex = /^\s*[a-zA-Z]{1}[0-9a-zA-Z][0-9a-zA-Z '-.=#/]*$/gmi; // Alternative syntax using RegExp constructor // const regex = new RegExp('^\\s*[a-zA-Z]{1}[0-9a-zA-Z][0-9a-zA-Z \'-.=#\/]*$', 'gmi') const str = `test=123 =test123 austin .,#/- Aberdeen Abilene Akron Albany Albu querque Alexandria Allentown Amarillo Anaheim Anchorage Ann Arbor Antioch Apple Valley Appleton Arlington Arvada Asheville Athens Atlanta Atlantic City Augusta Aurora Austin Bakersfield Baltimore Barnstable Baton Rouge Beaumont Bel Air Bellevue Berkeley Bethlehem Billings Birmingham Bloomington Boise Boise City Bonita Springs Boston Boulder Bradenton Bremerton Bridgeport Brighton Brownsville Bryan Buffalo Burbank Burlington Cambridge Canton Cape Coral Carrollton Cary Cathedral City Cedar Rapids Champaign Chandler Charleston Charlotte Chattanooga Chesapeake Chicago Chula Vista Cincinnati Clarke County Clarksville Clearwater Cleveland College Station Colorado Springs Columbia Columbus Concord Coral Springs Corona Corpus Christi Costa Mesa Dallas Daly City Danbury Davenport Davidson County Dayton Daytona Beach Deltona Denton Denver Des Moines Detroit Downey Duluth Durham El Monte El Paso Elizabeth Elk Grove Elkhart Erie Escondido Eugene Evansville Fairfield Fargo Fayetteville Fitchburg Flint Fontana Fort Collins Fort Lauderdale Fort Smith Fort Walton Beach Fort Wayne Fort Worth Frederick Fremont Fresno Fullerton Gainesville 9Garden Grove Garland Gastonia Gilbert Glendale Grand Prairie Grand Rapids Grayslake Green Bay GreenBay Greensboro Greenville Gulfport-Biloxi Hagerstown Hampton Harlingen Harrisburg Hartford Havre de Grace Hayward Hemet Henderson Hesperia Hialeah Hickory High Point Hollywood Honolulu Houma Houston Howell Huntington Huntington Beach Huntsville Independence Indianapolis Inglewood Irvine Irving Jackson Jacksonville Jefferson Jersey City Johnson City Joliet Kailua Kalamazoo Kaneohe Kansas City Kennewick Kenosha Killeen Kissimmee Knoxville Lacey Lafayette Lake Charles Lakeland Lakewood Lancaster Lansing Laredo Las Cruces Las Vegas Layton Leominster Lewisville Lexington Lincoln Little Rock Long Beach Lorain Los Angeles Louisville Lowell Lubbock Macon Madison Manchester Marina Marysville McAllen McHenry Medford Melbourne Memphis Merced Mesa Mesquite Miami Milwaukee Minneapolis Miramar Mission Viejo Mobile Modesto Monroe Monterey Montgomery Moreno Valley Murfreesboro Murrieta Muskegon Myrtle Beach Naperville Naples Nashua Nashville New Bedford New Haven New London New Orleans New York New York City Newark Newburgh Newport News Norfolk Normal Norman North Charleston North Las Vegas North Port Norwalk Norwich Oakland Ocala Oceanside Odessa Ogden Oklahoma City Olathe Olympia Omaha Ontario Orange Orem Orlando Overland Park Oxnard Palm Bay Palm Springs Palmdale Panama City Pasadena Paterson Pembroke Pines Pensacola Peoria Philadelphia Phoenix Pittsburgh Plano Pomona Pompano Beach Port Arthur Port Orange Port Saint Lucie Port St. Lucie Portland Portsmouth Poughkeepsie Providence Provo Pueblo Punta Gorda Racine Raleigh Rancho Cucamonga Reading Redding Reno Richland Richmond Richmond County Riverside Roanoke Rochester Rockford Roseville Round Lake Beach Sacramento Saginaw Saint Louis Saint Paul Saint Petersburg Salem Salinas Salt Lake City San Antonio San Bernardino San Buenaventura San Diego San Francisco San Jose Santa Ana Santa Barbara Santa Clara Santa Clarita Santa Cruz Santa Maria Santa Rosa Sarasota Savannah Scottsdale Scranton Seaside Seattle Sebastian Shreveport Simi Valley Sioux City Sioux Falls South Bend South Lyon Spartanburg Spokane Springdale Springfield St. Louis St. Paul St. Petersburg Stamford Sterling Heights Stockton Sunnyvale Syracuse Tacoma Tallahassee Tampa Temecula Tempe Thornton Thousand Oaks Toledo Topeka Torrance Trenton Tucson Tulsa Tuscaloosa Tyler Utica Vallejo Vancouver Vero Beach Victorville Virginia Beach Visalia Waco Warren Washington Waterbury Waterloo West Covina West Valley City Westminster Wichita Wilmington Winston Winter Haven Worcester Yakima Yonkers York Youngstown`; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions