re = /([a-zA-Z ]+),/
str = 'California
Alameda, CA
Albany, CA
Altadena, CA
Alviso, CA
Atherton, CA
Belmont, CA
Berkeley, CA
Beverly Hills, CA
Burbank, CA
Burlingame, CA
Campbell, CA
Culver City, CA
Cupertino, CA
El Cerrito, CA
Emeryville, CA
Encino, CA
Glendale, CA
La Canada Flintridge, CA
Los Altos, CA
Los Angeles, CA
Los Gatos, CA
Marina Del Rey, CA
Menlo Park, CA
Millbrae, CA
Mountain View, CA
North Hollywood, CA
Oakland, CA
Pacific Palisades, CA
Palo Alto, CA
Pasadena, CA
Playa Del Rey, CA
Portola Valley, CA
Redwood City, CA
Reseda, CA
San Bruno, CA
San Carlos, CA
San Francisco, CA
San Jose, CA
San Leandro, CA
San Marino, CA
San Mateo, CA
Santa Clara, CA
Santa Monica, CA
Saratoga, CA
Sherman Oaks, CA
South Pasadena, CA
South San Francisco, CA
Stanford, CA
Studio City, CA
Sunnyvale, CA
Tarzana, CA
Valley Village, CA
Van Nuys, CA
Venice, CA
West Hollywood, CA
Colorado
Boulder, CO
Denver, CO
Englewood, CO
Lafayette, CO
Louisville, CO
Connecticut
Canaan, CT
East Canaan, CT
Falls Village, CT
Lakeville, CT
Norfolk, CT
Salisbury, CT
Sharon, CT
Stamford, CT
West Cornwall, CT
District of Columbia
Washington, DC
Florida
Key Biscayne, FL
Miami Beach, FL
Miami, FL
North Miami Beach, FL
Georgia
Alpharetta, GA
Atlanta, GA
Avondale Estates, GA
Decatur, GA
Marietta, GA
Roswell, GA
Scottdale, GA
Smyrna, GA
Illinois
Aurora, IL
Buffalo Grove, IL
Chicago, IL
Clarendon Hills, IL
Deerfield, IL
Downers Grove, IL
Elmhurst, IL
Evanston, IL
Fort Sheridan, IL
Glencoe, IL
Glenview Nas, IL
Glenview, IL
Grayslake, IL
Highland Park, IL
Highwood, IL
Hinsdale, IL
Kenilworth, IL
Lake Bluff, IL
Lake Forest, IL
Lake Zurich, IL
Libertyville, IL
Lincolnshire, IL
Lincolnwood, IL
Lisle, IL
Mundelein, IL
Naperville, IL
Northbrook, IL
Oak Brook, IL
Prospect Heights, IL
Skokie, IL
Vernon Hills, IL
Villa Park, IL
Warrenville, IL
Westmont, IL
Wheeling, IL
Wilmette, IL
Winnetka, IL
Indiana
Carmel, IN
Fishers, IN
Indianapolis, IN
Maryland
Bethesda, MD
Cabin John, MD
Chevy Chase, MD
Gaithersburg, MD
Garrett Park, MD
Kensington, MD
Potomac, MD
Rockville, MD
Silver Spring, MD
Takoma Park, MD
Massachusetts
Allston, MA
Arlington, MA
Ashley Falls, MA
Auburndale, MA
Babson Park, MA
Belmont, MA
Boston, MA
Brighton, MA
Brookline, MA
Cambridge, MA
Charlestown, MA
Chestnut Hill, MA
Jamaica Plain, MA
Medford, MA
Needham, MA
New Town, MA
Newton Center, MA
Newton Highlands, MA
Newton Lower Falls, MA
Newton Upper Falls, MA
Newton, MA
Newtonville, MA
Roslindale, MA
Sheffield, MA
Somerville, MA
South Egremont, MA
Waban, MA
Waltham, MA
Watertown, MA
Wellesley Hills, MA
Wellesley, MA
West Newton, MA
Michigan
Ann Arbor, MI
Birmingham, MI
Bloomfield Hills, MI
Chelsea, MI
Commerce Township, MI
Dexter, MI
Farmington, MI
Franklin, MI
Keego Harbor, MI
Novi, MI
Plymouth, MI
Rochester, MI
Royal Oak, MI
Saline, MI
Southfield, MI
Troy, MI
Walled Lake, MI
Waterford, MI
West Bloomfield, MI
Ypsilanti, MI
Minnesota
Hopkins, MN
Minneapolis, MN
Saint Paul, MN
New Jersey
Bloomfield, NJ
Caldwell, NJ
Cedar Grove, NJ
Clifton, NJ
Elmwood Park, NJ
Fair Lawn, NJ
Fairfield, NJ
Garfield, NJ
Haledon, NJ
Lincoln Park, NJ
Little Falls, NJ
Montclair, NJ
New York, NJ
Nutley, NJ
Passaic, NJ
Paterson, NJ
Pequannock, NJ
Rutherford, NJ
Saddle Brook, NJ
Totowa, NJ
Verona, NJ
Wayne, NJ
New York
Amenia, NY
Ancramdale, NY
Arverne, NY
Astoria, NY
Bayside, NY
Bellerose, NY
Breezy Point, NY
Brooklyn, NY
Cambria Heights, NY
College Point, NY
Copake, NY
Corona, NY
East Elmhurst, NY
Elmhurst, NY
Far Rockaway, NY
Flushing, NY
Forest Hills, NY
Fresh Meadows, NY
Hollis, NY
Howard Beach, NY
Jackson Heights, NY
Jamaica, NY
Kew Gardens, NY
Little Neck, NY
Long Island City, NY
Maspeth, NY
Middle Village, NY
Millerton, NY
New York, NY
Oakland Gardens, NY
Ozone Park, NY
Pine Plains, NY
Queens Village, NY
Rego Park, NY
Richmond Hill, NY
Ridgewood, NY
Rockaway Park, NY
Rosedale, NY
Saint Albans, NY
South Ozone Park, NY
South Richmond Hill, NY
Springfield Gardens, NY
Sunnyside, NY
Whitestone, NY
Woodhaven, NY
Woodside, NY
Oregon
Beaverton, OR
Hillsboro, OR
Lake Oswego, OR
Portland, OR
Tualatin, OR
West Linn, OR
Pennsylvania
Abington, PA
Ambler, PA
Ardmore, PA
Bala Cynwyd, PA
Bensalem, PA
Berwyn, PA
Blue Bell, PA
Bridgeport, PA
Bryn Athyn, PA
Bryn Mawr, PA
Cheltenham, PA
Collegeville, PA
Conshohocken, PA
Devon, PA
Dresher, PA
Drexel Hill, PA
Elkins Park, PA
Flourtown, PA
Fort Washington, PA
Gladwyne, PA
Glenside, PA
Gwynedd Valley, PA
Gwynedd, PA
Haverford, PA
Havertown, PA
Huntingdon Valley, PA
Jenkintown, PA
King Of Prussia, PA
Lafayette Hill, PA
Lansdale, PA
Lansdowne, PA
Malvern, PA
Merion Station, PA
Mont Clare, PA
Montgomeryville, PA
Narberth, PA
Norristown, PA
North Wales, PA
Oreland, PA
Paoli, PA
Philadelphia, PA
Phoenixville, PA
Plymouth Meeting, PA
Upper Darby, PA
Villanova, PA
Wayne, PA
Willow Grove, PA
Wyncote, PA
Wynnewood, PA
Texas
Austin, TX
Bellaire, TX
Cedar Park, TX
Conroe, TX
Houston, TX
Katy, TX
Pflugerville, TX
Round Rock, TX
Sandy, TX
Spring, TX
Virginia
Alexandria, VA
Arlington, VA
Dunn Loring, VA
Falls Church, VA
Ft Myer, VA
McLean, VA
Washington
Bellevue, WA
Kirkland, WA
Lynnwood, WA
Medina, WA
Mercer Island, WA
Mountlake Terrace, WA'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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