I am attempting to extract a part number from a string. I am going to iterate over items, and need to extract the item if it is over 4 characters long, and contains AT LEAST 1 number. It does not have to include letters, but can.
For instance:
Line1: 'There is some random information here'
Line2: 'This includes item p23344dd5 as well as other info'
Line3: 'K3455 $100.00'
Line4: 'Last part number here 5551234'
What I need is to extract the 3 item numbers, p23344dd5, K3455, and 5551234.
I am using this code, but it just returns if it matches, which is not what i need. I need to return the matched text.
import re
items = ['There is some random information here',
'This includes item p23344dd5 as well as other info',
'K3455 $100.00',
'Line4: ''Last part number here 5551234']
for item in items:
x = re.search(r'^(?=.*\d).{5,}$', item)
print(x)
$100.00is over 4 characters long and contains at least one number. What constitutes a word boundary?