Python regex: Finding input not matching a specific (variable-defined) length -
i'm writing regular expressions in python, keep getting problem:
typeerror: 'int' object not iterable.
my regular expression:
searchresults = (re.findall("[0-9]{"+re.escape(columns)"}",content))
my variable columns length of first element of set (len(..)) of regular expression. when i'm using normal number works. when try print(columns), see normal number.
thanks help!
sample of content:
111111111111 100111011101 180101020111 1001010000112 101610170051 150100111001 101100111101 100010000111 100000801111 100081010111 111111111111
sample columns: 12
as result i'm trying line (which not have 12 numbers): 1001010000112
if want filter strings of not matching specific length, following trick:
re.findall('(^[0-9]{0,%d}$|[0-9]{%d}[0-9])' % (columns, columns), s)
Comments
Post a Comment