python regex to split list entry's name into list name and index -


how can use regular expressions parse <listname>[#] [listname, #]?

here's i've tried:

> s = 'li[10]' > re.split(s,r'[%d]') ['[%d]'] > re.findall(s,r'[%d]') [] > s.split(r'[%d]') ['li[0]'] 

the desired output li , 10

how (.*)\[(.*)\]?

re.findall("(.*)\[(.*)\]", s)  # [('li', '10')] 

Comments