[英]Regex: How do I exclude commas when in my pattern?
I want to find the first number that is sandwiched with commas on either end, and I came up with this: 我想找到第一个数字,两端都用逗号隔开,然后我想到了:
m = re.search("\,([0-9])*\,",line)
However, this returns to me the number with the commas, how do I exclude them? 但是,这给我返回带逗号的数字,如何排除它们?
m.group(0)
returns m.group(0)
返回
',1620693,'
group(0)
will always return the entire match. group(0)
将始终返回整个匹配项。
See python documentation: 请参阅python文档:
>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
>>> m.group(0) # The entire match
'Isaac Newton'
>>> m.group(1) # The first parenthesized subgroup.
'Isaac'
Use m.group(1)
. 使用m.group(1)
。 You also don't need to escape (backslash) the commas. 您也不需要转义(反斜杠)逗号。 m.group(0)
refers to the entire match, and each number after that refers to matched groups. m.group(0)
表示整个匹配项,其后的每个数字表示匹配的组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.