我是regex的新手,必须在语法上缺少一些愚蠢的东西
我的代码:
import re
numberString = '42 1,234 342,111,234 23,23,34 1234'#regex to match first 3 values and not last 2
regtext = re.compile(r'^\d{1,3}(,\d{3})*$')
#^\d{1,3} Find a 1 to 3 digit number to start
#(,\d{3})*$ Find 0 or more cases of a comma and three digits at the end
matchingNumbers = regtext.findall(numberString)
我尝试过不同版本的正则表达式,并使用了几种在线正则表达式工具,说匹配是正确的,但它为我返回了一个空字符串。
如果要进行多个匹配,则不应使用^
和$
:
regtext = re.compile(r'\d{1,3}(,\d{3})*')