Reputation: 591
The problem seems to be directly originated by the pattern, It's supposed to filter
I'm pasting my code bellow, please tell me if there's any particular problem and thanks in advance.
patterns = [r'^{5}[0-9],2[0-9a-fA-F] $'] #pattern list
class IterPat:
def __init__(self, lect, pat = patterns):
self.pat = pat # lista de patrones posibles para sensores
self.lect = lect # lectura siendo analizada
#self.patLen = len(pat) #Largo de patrones // no sabemos si lo usaremos
'''
Primero revisa si ya pasamos por todas las iteraciones posibles
luego revisa si la iteración es la que pensabamos, de ser así regresa una
tupla con el patrón correspondiente, y la lectura
de otra forma para el valor de ser mostrado
'''
def Iterar(self):
for self.iteracion in self.pat:
#problem seem sto originate here
pattern = re.compile(self.iteracion)
comp = pattern.match(self.lect)
if comp == True:
re_value = (self.pattern, self.lect)
return re_value
Upvotes: 0
Views: 68
Reputation: 189799
Like the error message says, the quantifier expression {5}
cannot follow nothing. You seem to be trying to use it as a prefix operator, but it is a postfix operator. Thus, r'[0-9]{5}'
etc. where you could substitute the shorthand \d
for the digit character class.
And of course a literal 2
will simply match the literal number two. You need the braces to make it a quantifier. So [0-9a-fA-F]{2}
or simply \x{2}
.
Upvotes: 1