I have a string formatted as results_item12345. The numeric part is either four or five digits long. The letters will always be lowercase and there will always be an underscore somewhere in the non-numeric part.
I tried to extract it using the following:
import re
string = 'results_item12345'
re.search(r'[^a-z][\d]',string)
However, I only get the leftmost two digits. How can I get the entire number?
Assuming you only care about the numbers at the end of the string, the following expression matches 4 or 5 digits at the end of the string.
\d{4,5}$
Otherwise, the following would be the full regex matching the provided requirements.
^[a-z_]+\d{4,5}$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With