0

I have this string

mod = 'ketobutyric_arp_rm(12);oxidation+%28hw%29(19)'

and want to get the numbers in parentheses as a list some kind of similar to:

mod_pos = ['12','19']

Using split seems to be a bit circuitous, and I don't know how to use a find method on this.

Any suggestions how I can do this?

J0e3gan
  • 8,570
  • 9
  • 52
  • 78

2 Answers2

1

Here is one way:

>>> import re
>>> mod='ketobutyric_arp_rm(12);oxidation+%28hw%29(19)'
>>> re.findall(r'\((\d+)\)', mod)
['12', '19']
Irshad Bhat
  • 7,941
  • 1
  • 21
  • 32
0

Use regular expressions. import re m=re.match(r'((\d+))', string) This would return matched patterns in a tuple which u can fetch by m.group(1) etc..