[Solved] how to extract digits from a string? [closed]


Based on the expected output, you want more than just digits. The digits can have /, - and ,.

Maybe, perhaps, you wanted something that starts with and ends with a digit, but anything in the middle other than a space?

import re
a="invoice β invoice # 2018-33167-2 β date 03/21/2018 β total due $8,804.90"
print(re.findall(r'\d[^ ]+\d', a))

output

python3 test.py
['2018-33167-2', '03/21/2018', '8,804.90']

1

solved how to extract digits from a string? [closed]