Q:

Regex to separate City and State from input string

I have some input strings.
Houston, TX
(Houston, TX)
South & West (Houston, TX)
(South & West (Houston, TX))

I am using this pattern but it's not working for all four.
.*\(*(.*),\s*(.*)\)*

I just want Houston and TX out of above input strings.
The rules are to take take the stuff out which is inside parenthesis or if there are no parenthesis just the stuff. Resulting list will just have 2 items in it. 

A:

Have a look at the python Regular Expression operations page - I found it useful when learning how to do these type of things.
I'm not sure if you wanted to separate out the city & state or not, but you can do so using groups like so:
import re

string = ('Houston, TX ' +
         '(San Francisco, CA) ' +
         'South & West (Houston, TX) ' +
         '(South & West (Houston, TX))')

matches = re.findall("([\w\s]+),\s(\w+)", string)
for match in matches:
    print 'City: ' + match[0] + ', State: ' + match[1]

Outputs:
City: Houston, State: TX
City: San Francisco, State: CA
City: Houston, State: TX
City: Houston, State: TX

Regular Expression:
([\w\s]+) Group 1: Matches multiple words with spaces
,\s comma followed by a space
(\w+) Group 2: Matches a single word

