When trying to use the re module in Pythonista - I get some weird behavior. Specifically the re.sub method doesn't work as documented. Here's my code with sample text. This has been tested in multiple python regex "testers" (e.g. http://regex101.com/r/yP7bA9/1 )
import re
scores = [[u'Orlando 81 Washington 90 (3:55 IN 4TH)'], [u'Atlanta 59 Cleveland 87 (3:51 IN 3RD)'], [u'Utah 62 Toronto 69 (3:59 IN 3RD)'], [u'Indiana 46 Chicago 42 (0:03 IN 2ND)'], [u'Detroit 50 Memphis 51 (0:18 IN 2ND)'], [u'Minnesota 22 Dallas 28 (0:00 IN 1ST)'], [u'Brooklyn at Portland (10:00 PM ET)'], [u'San Antonio at Sacramento (10:00 PM ET)'], [u'Charlotte at Golden State (10:30 PM ET)'], [u'Phoenix at LA Clippers (10:30 PM ET)']]
for score in scores:
print score
print re.sub('([a-zA-Z^ ]+?)(\\d+|at)\\s+?([a-zA-Z^ ]+?)(\\d+)?\\s+?(\\(.+\\))\\s+?', 'whatever replacment', score[0])
and the sample text is (there are extra spaces on the end of some lines) - it's an array of arrays:
Orlando 38 Washington 46 (1:36 IN 2ND)
Atlanta 25 Cleveland 37 (0:28 IN 1ST)
Utah 25 Toronto 23 (0:00 IN 1ST)
Indiana at Chicago (8:00 PM ET)
Detroit at Memphis (8:00 PM ET)
Minnesota at Dallas (8:30 PM ET)
Brooklyn at Portland (10:00 PM ET)
San Antonio at Sacramento (10:00 PM ET)
Charlotte at Golden State (10:30 PM ET)
Phoenix at LA Clippers (10:30 PM ET)
The weird thing is that this seems to work when not in a for loop.....