I have following example of american addresses.
6301 Stonewood Dr Apt-728, Plano TX-75024
13323 Maham Road, Apt # 1621, Dallas, TX 75240
17040 Carlson Drive, #1027 Parker, CO 80134
3465 25th St., San Francisco, CA 94110
I want to extract city from using regex
Plano, Dallas, Parker, San Francisco
I am using following regex which is working for first example
(?<=[,.|•]).*\s+(?=[\s,.]?CA?[\s,.-]?[\d]{4,})
can you help me for the same as?
You can match the comma, then all except A-Z and capture from the first occurrence of A-Z.
,[^A-Z,]*?\b([A-Z][^,]*?),?\s*[A-Z]{2}[-\s]\d{4,}\s*$
Explanation
,[^A-Z,]*?\b
Match a comma, then any char except A-Z or a comma till a word boundary([A-Z][^,]*?)
Capture group 1 Match A-Z and then any char except a comma as least as possible,?\s*[A-Z]{2}
match optional comma, optional whiteapace chars and 2 uppecase chars A-Z[-\s]\d{4,}\s*
Match either - or a whitespace char and then 4 or more digits followed by optional whiteapace chars$
end of string