I am trying to match strings that starts with a letter followed by 2,6 digits anywhere in the line using the following regex ,the following regex matches R77 but not J123, can anyone provide guidance on how to fix this?
import re
code_free = "[KG6.R77.1.2][J123-P1A-00194]/12C114"
o = re.search(r'(^|[^a-zA-Z0-9:])([a-zA-Z](\d{2,6}[a-zA-Z]?|\d{1}[xX]{1,2}))([^a-zA-Z0-9]|AP|DEV|$)', code_free)
print (o.group(2))