arrays - Python Splitting string by number and space -


hy, please me? have lot of strings contain addresses , need split them street name, house number , country in array.

something this:

streeta 15, new york street number 2 35, california streetb 36b, texas 

into:

['streeta','15','new york'] ['street number 2','35','california'] ['streetb','36b','texas'] 

thank you.

you don't need use re.compile():

import re  def splitup(string):     match = re.search(" \\d[^ ]*, ", string)     if match none:         raise valueerror("not valid string: %r" % string)     street = string[:match.start()]     number = string[match.start(): match.end()].strip(", ")     state = string[match.end():]     return [street, number, state] 

for examples, prints:

['streeta', '15', 'new york'] ['street number 2', '35', 'california'] ['streetb', '36b', 'texas'] 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -