简体   繁体   English

捕获此正则表达式中的数字

[英]Capture the numbers in this regex

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM