繁体   English   中英

使用 Python "Regex" 查找单词

[英]Find word with Python "Regex"

你能帮忙吗:我想使用 python 从该文本中获取地址:

 [RIPH] harambe protocol

First alert listed in this telegram group 637 seconds before anyone else.

Coin name:    harambe protocol
Address:         0x10964C2ffDEA1e99B5e26D102516d9b03368915f
Platform:        BSC
Time:               08:02:58 UTC

尝试这个:

import re

pattern = "Address:.*(0x.*)"

address = re.findall(pattern, your_text, re.MULTILINE)

print(address)

请您尝试以下方法:

#!/usr/bin/python

import re

with open('textfile') as f:
    for line in f:
        m = re.search(r'Address:\s*(0[xX][0-9A-Fa-f]+)', line)
        if (m):
            print(m.group(1))

Output:

0x10964C2ffDEA1e99B5e26D102516d9b03368915f

暂无
暂无

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

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