I'm doing a regex on a string to find a certain pattern:
fileName = '123456_BI12554_AA_0021.jpg'
id = re.findall(r'(_BI\d{5}_)', fileName)
Which finds _BI12554_ but sometimes there are 6 digits and not just 5.
Is there a way to find all the digits between _BI and _ regardless of how many there are?
Yes of course: you can use + to mean "1 or more" digits.
re.findall(r'(_BI\d+_)', fileName)
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