在Python中使用Regex获得数字的平静
我正在尝试使用 Python 中的正则表达式获取数字的一部分,我想收集 0(零)数字之后的数字序列,如下所示:
S_9900002127
S_9900000719
S_9900008012
因此,在上面的示例中我想获取:2127, 719和8012
,我已经完成了正则表达式:
r'(_9(\d*)[.^0](\d*))'
并得到了第二组正则表达式:[2]
,但结果是:2127、719和12.
.
请注意,第三个忽略数字 8
,因为 0
(零)。
有人可以帮我得到正确的结果2127、719和8012
吗???
I´m trying to get a part of number using Regex in Python, I want to collect the sequence of numbers after 0 (zero) number, like this:
S_9900002127
S_9900000719
S_9900008012
So, in this example above I want to get: 2127, 719 and 8012
, and I have done the Regex:
r'(_9(\d*)[.^0](\d*))'
and get the second group of Regex: [2]
, but the result is: 2127, 719 and 12
.
Look that the third one ignore the number 8
because the 0
(zero).
Could someone help me to get the correct result 2127, 719 and 8012
???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
查看 Python 演示 和 正则表达式演示。 详细信息:
0+
- 一个或多个0
([1-9]\d*)
- 组1:一个非零数字,然后零个或多个数字$
- 行尾。You can use
See the Python demo and the regex demo. Details:
0+
- one or more0
s([1-9]\d*)
- Group 1: a non-zero digit and then zero or more digits$
- end of a line.