24 lines
870 B
Python
24 lines
870 B
Python
import re
|
|
|
|
def parse(text):
|
|
# Regular expressions for different Bitcoin address formats
|
|
p2pkh_regex = r'\b1[1-9A-HJ-NP-Za-km-z]{25,34}\b'
|
|
p2sh_regex = r'\b3[1-9A-HJ-NP-Za-km-z]{25,34}\b'
|
|
bech32_regex = r'\bbc1[q,p,z][0-9a-z]{39,59}\b'
|
|
bech32_regex1 = r'\bbc1[qpz0-9ac-hj-np-z]{38,58}\b'
|
|
less_common_regex = r'\b[13][a-km-zA-HJ-NP-Z1-9]{25,34}\b'
|
|
|
|
# Combine all regexes
|
|
combined_regex = f'({p2pkh_regex})|({p2sh_regex})|({bech32_regex})|({less_common_regex}) | ({bech32_regex1})'
|
|
|
|
matches = []
|
|
for match in re.finditer(combined_regex, text):
|
|
for addr in match.groups():
|
|
if addr: # Check if the captured group is not None
|
|
start_pos, end_pos = match.span()
|
|
matches.append((addr, start_pos, end_pos))
|
|
|
|
return matches
|
|
|
|
# integrate regexes xpub, ypub, zpub
|
|
# checksumme check |