hi i have a string like this
track._Event('product', 'test');Product.lisen(1234, 21, 4343); return false;
i want to use some regular expression so i would end up with groups
pid = 1234
p1 = 21
p2 = 4343
hi i have a string like this
track._Event('product', 'test');Product.lisen(1234, 21, 4343); return false;
i want to use some regular expression so i would end up with groups
pid = 1234
p1 = 21
p2 = 4343
import re
s = "track._Event('product', 'test');Product.lisen(1234, 21, 4343); return false;"
pattern = re.compile(r'.*lisen\((?P<pid>\d+),\s*(?P<p1>\d+),\s*(?P<p2>\d+)\).*')
pid, p1, p2 = map(int, pattern.match(s).groups())
Note: I used named capturing groups, but that is not necessary in this case.
Why regular expression? you can do it will simple string manipulations
>>> s="track._Event('product', 'test');Product.lisen(1234, 21, 4343); return false;"
>>> s.split("lisen(")[-1].split(")")[0].split(",")
['1234', ' 21', ' 4343']