如何在多字符串变量中的特定文本后使用正则表达式匹配随机数?
在python中,我想通过在多字符串变量中搜索“Beginning Supply”来捕获一个随机数“100000000000000000”,如下所示,
import re
message = """Test
- 55244
Graph
- Tools
Beginning Supply
- 100000000000000000
Name
- Text2
Type"""
pattern = re.compile(r"Total.Supply...(\d+)")
pattern.match(message)
In python, I want to capture a random number lets say '100000000000000000' by searching for 'Beginning Supply' in a multi string variable as shown below,
import re
message = """Test
- 55244
Graph
- Tools
Beginning Supply
- 100000000000000000
Name
- Text2
Type"""
pattern = re.compile(r"Total.Supply...(\d+)")
pattern.match(message)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
.
不捕获\n
字符。为了实现这一点,您必须在模式中使用DOTALL
标志。如果你想使用
match
:如果你想使用
findall
:注意:
re.match
必须匹配整个字符串,否则它将返回无
By default,
.
does not capture\n
characters. In order to achieve that you must use theDOTALL
flag in your pattern.If you want to use
match
:If you want to use
findall
:NOTE:
re.match
must match the entire string or else it will returnNone