So I have a bunch of strings that contain a sequence of numbers and dashes:
strings = [
'32sdjhsdjhsdjb20-11-3kjddjsdsdj435',
'jdhjhdahj200-19-39-2-12-2jksjfkfjkdf3345',
'1232sdsjsdkjsop99-7-21sdjsdjsdj',
]
I have a function:
def get_nums():
for string in strings:
print(re.findall('\d+-\d+', string))
I want this function to return the following:
['20-11-3']
['200-19-39-2-12-2']
['99-7-21']
But my function returns:
['20-11']
['200-19', '39-2', '12-2']
['99-7']
I have no idea how to return the full sequence of numbers and dashes.
The sequences will always begin and end with numbers, never dashes. If there are no dashes between the numbers they should not be returned.
How can I use regex to return these sequences? Is there an alternative to regex that would be better here?