Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

regex city and state

// street, city and state must be separated by '.' or ','
const addressStr = '123 Main St., New York, NY 10001, USA';

const cityAndState = addressStr
						.match(/([A-Z][a-z]+s?)+,s[A-Z]{2}/g)
						.toString();

console.log(cityAndState);
// New York, NY
 
PREVIOUS NEXT
Tagged: #regex #city #state
ADD COMMENT
Topic
Name
4+4 =