I have a string like this:
{{1090872, "A"}, {4281, "AA"}, {1332552, "AAACU"}, {1287145, "AABB"}}
How can I write a regex to capture the numbers. I know that I can capture the letters with: "(.*?)"
If you don't have number in quotes, then answer is
import re
str = '{{1090872, "A"}, {4281, "AA"}, {1332552, "AAACU"}, {1287145, "AABB"}}'
re.findall(r'\d+', str)
['1090872', '4281', '1332552', '1287145']
otherwise you can try
re.findall(r'[{},](\d+)[{},]', str)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.