List comprenehsion that gets regex to be executed

Viewed 37

I don't know what's wrong with this. I have a list of items:

int=['xe-0/1/1', 'xe-0/1/2', 'xe-0/1/3', 'xe-0/2/2', 'xe-0/2/3', 'xe-0/3/1', 'xe-1/0/2', 'xe-1/0/3', 'xe-1/1/1', 'xe-1/1/2', 'xe-1/2/2', 'xe-1/2/3', 'xe-1/3/1', 'xe-1/3/2', 'xe-2/0/2', 'xe-2/0/3', 'xe-2/1/1', 'xe-2/1/2', 'xe-2/1/3', 'xe-2/2/2', 'xe-2/2/3', 'xe-2/3/1', 'xe-2/3/2', 'xe-3/0/2', 'xe-3/0/3', 'xe-3/1/2', 'xe-3/1/3', 'xe-3/2/1', 'xe-3/2/2', 'xe-3/2/3', 'xe-3/3/2', 'xe-4/0/2', 'xe-4/0/3', 'xe-4/1/2', 'xe-4/1/3', 'xe-4/2/2', 'xe-4/2/3', 'xe-4/3/2', 'xe-4/3/3', 'xe-7/3/3', 'xe-8/0/7', 'xe-8/3/6', 'xe-8/3/7', 'xe-9/0/5', 'xe-9/0/6', 'xe-9/0/7', 'xe-9/1/5', 'xe-9/1/6', 'xe-10/0/4', 'xe-10/0/6', 'xe-10/0/7', 'xe-10/1/6', 'xe-10/2/4', 'xe-10/2/6', 'xe-10/2/7', 'xe-10/3/7', 'xe-11/0/6', 'xe-11/0/7', 'xe-11/1/6', 'xe-11/1/7', 'xe-11/2/6', 'xe-11/2/7', 'xe-11/3/6', 'xe-11/3/7']

and I want to iterate this list and get two new lists that contains only a match that I define in the regex.

for i in range(2):
    regex="xe-%s/1/*" %i
    print regex
    [x for x in int if re.match(r'regex',x)]

Result:

xe-0/1/* [] xe-1/1/* []

But it seems that doesn't work.

1 Answers
Related